Created
October 9, 2017 16:57
-
-
Save dhilipsiva/846b5b2b465ca046f3993ba2c1c8891e to your computer and use it in GitHub Desktop.
Flatten
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(items): | |
new_items = [] | |
for item in items: | |
if type(item) == int: | |
new_items.append(item) | |
else: | |
new_items += flatten(item) | |
return new_items | |
print(flatten([[1,2,[3]],4])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment