Created
November 25, 2018 14:59
-
-
Save Deepakkoli93/cf35013263f540d1ce273c2e3eb2186c to your computer and use it in GitHub Desktop.
flatten a list
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): | |
if len(l) == 0: | |
return [] | |
first = l[0] | |
if type(first) is list: | |
return flatten(first) + flatten(l[1:]) | |
else: | |
return [first] + flatten(l[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment