Skip to content

Instantly share code, notes, and snippets.

@mlevans
Last active December 19, 2015 20:09
Show Gist options
  • Save mlevans/6011711 to your computer and use it in GitHub Desktop.
Save mlevans/6011711 to your computer and use it in GitHub Desktop.
flatten an irregular multidimensional list
import collections
def flatten(x):
if isinstance(x, collections.Iterable):
return [a for i in x for a in flatten(i)]
else:
return [x]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment