Complete the expand method.
Some flake8 fixes.

Also added a utility method for determining the result of a list
operation.