Skip to content

Instantly share code, notes, and snippets.

@mcho421-snippets
Created December 9, 2012 05:12
Show Gist options
  • Save mcho421-snippets/4243437 to your computer and use it in GitHub Desktop.
Save mcho421-snippets/4243437 to your computer and use it in GitHub Desktop.
Python: Flatten irregular list of lists
def flatten(l):
for el in l:
if isinstance(el, collections.Iterable) and not isinstance(el, basestring):
for sub in flatten(el):
yield sub
else:
yield el
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment