Skip to content

Instantly share code, notes, and snippets.

@x-fran
Last active December 11, 2017 13:07
Show Gist options
  • Save x-fran/7c2e293429253402b64a854d1935e2cb to your computer and use it in GitHub Desktop.
Save x-fran/7c2e293429253402b64a854d1935e2cb to your computer and use it in GitHub Desktop.
Simple function to flatten multidimensional lists in python
def flatten(lst):
"""
Flatten nested lists
:param lst: Nested list. Any depth
:return: flat list
"""
for e in lst[:]:
if type(e) is list:
lst.remove(e)
lst += flatten(e)
lst.sort()
return lst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment