Skip to content

Instantly share code, notes, and snippets.

@anilpai
Created February 2, 2017 01:29
Show Gist options
  • Save anilpai/01236f830a58571cd95c66953d3d9097 to your computer and use it in GitHub Desktop.
Save anilpai/01236f830a58571cd95c66953d3d9097 to your computer and use it in GitHub Desktop.
Flatten a list
def flatten(lst):
'''
Flattens a list of lists.
'''
r = []
for x in lst:
if type(x) is list:
r.extend(x)
else:
r.append(x)
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment