Skip to content

Instantly share code, notes, and snippets.

@tharun323
Created June 14, 2018 14:43
Show Gist options
  • Save tharun323/59827582ba22a32c2fb72675b380e9aa to your computer and use it in GitHub Desktop.
Save tharun323/59827582ba22a32c2fb72675b380e9aa to your computer and use it in GitHub Desktop.
Code,that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers
flatten = lambda x: [y for l in x for y in flatten(l)] if type(x) is list else [x]
a = [1, 2, [3, 4], [[5, 6], [7, 8]]]
print flatten(a)
# This will print a list [1, 2, 3, 4, 5, 6, 7, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment