Skip to content

Instantly share code, notes, and snippets.

@ryanpeach
Created April 26, 2020 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanpeach/e57a5e17cdc685b734351a4d5f8bd3c7 to your computer and use it in GitHub Desktop.
Save ryanpeach/e57a5e17cdc685b734351a4d5f8bd3c7 to your computer and use it in GitHub Desktop.
Flatten
import collections
def flatten(l):
for el in l:
if isinstance(el, collections.Iterable) and not isinstance(el, (str, bytes)):
yield from flatten(el)
else:
yield el
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment