Skip to content

Instantly share code, notes, and snippets.

@caffeine-potent
Created August 21, 2018 19:15
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 caffeine-potent/5166cd2baab30308e89741cb88aa059a to your computer and use it in GitHub Desktop.
Save caffeine-potent/5166cd2baab30308e89741cb88aa059a to your computer and use it in GitHub Desktop.
Flatten Lists and Tuples
from functools import reduce
flatten = lambda lst: reduce(lambda l, i: l + flatten(i) if isinstance(i, (list, tuple)) else l + [i], lst, [])
test = [[[[1,0],1],0],1]
print(flatten(test))
## Credit https://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment