Skip to content

Instantly share code, notes, and snippets.

@axiaoxin
Created March 31, 2015 17:31
Show Gist options
  • Select an option

  • Save axiaoxin/aaeeb6cab8d997efa48a to your computer and use it in GitHub Desktop.

Select an option

Save axiaoxin/aaeeb6cab8d997efa48a to your computer and use it in GitHub Desktop.
flatten = lambda lst: reduce(lambda l, i: l + flatten(i) if isinstance(i, (list, tuple)) else l + [i], lst, [])
print flatten([2, [2, [4, 5, [7], [2, [6, 2, 6, [6], 4]], 6]]])
# [2, 2, 4, 5, 7, 2, 6, 2, 6, 6, 4, 6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment