Skip to content

Instantly share code, notes, and snippets.

@monolithed
Created February 23, 2013 19:21
Show Gist options
  • Save monolithed/5020946 to your computer and use it in GitHub Desktop.
Save monolithed/5020946 to your computer and use it in GitHub Desktop.
def flatten (*args):
for x in args:
if hasattr(x, '__iter__'):
for y in flatten(*x):
yield y
else:
yield x
# flatten(1, 2, [3, 4, 5]) = [1, 2, 3, 4, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment