Skip to content

Instantly share code, notes, and snippets.

@Deepakkoli93
Created November 25, 2018 14:59
Show Gist options
  • Save Deepakkoli93/cf35013263f540d1ce273c2e3eb2186c to your computer and use it in GitHub Desktop.
Save Deepakkoli93/cf35013263f540d1ce273c2e3eb2186c to your computer and use it in GitHub Desktop.
flatten a list
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