Created
November 18, 2018 07:14
-
-
Save yjzhang/b9d26f6bf5dd07b79b9c9a909a3c2904 to your computer and use it in GitHub Desktop.
flattening a list 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(l): | |
output = [] | |
for x in l: | |
try: | |
output += flatten(x) | |
except: | |
output.append(x) | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment