Skip to content

Instantly share code, notes, and snippets.

@trsqxyz
Last active September 1, 2015 05:20
Show Gist options
  • Save trsqxyz/007fc70d23f6464b26d2 to your computer and use it in GitHub Desktop.
Save trsqxyz/007fc70d23f6464b26d2 to your computer and use it in GitHub Desktop.
def flatten(x):
if hasattr(x, '__iter__') and not isinstance(x, str):
for y in x:
yield from flatten(y)
else:
yield x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment