Last active
December 11, 2017 13:07
-
-
Save x-fran/7c2e293429253402b64a854d1935e2cb to your computer and use it in GitHub Desktop.
Simple function to flatten multidimensional lists in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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