Skip to content

Instantly share code, notes, and snippets.

@escuccim escuccim/flatten.py
Created Apr 17, 2018

Embed
What would you like to do?
Python Function to Flatten Nested Lists
# this works just like "unlist" in R
def flatten(l):
out = []
for item in l:
if isinstance(item, (list, tuple)):
out.extend(flatten(item))
else:
out.append(item)
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.