Skip to content

Instantly share code, notes, and snippets.

@debuggerpk
Created September 27, 2018 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debuggerpk/40ab93ec18e790e71368041c517551f5 to your computer and use it in GitHub Desktop.
Save debuggerpk/40ab93ec18e790e71368041c517551f5 to your computer and use it in GitHub Desktop.
Flattens a nested array
def flatten(nested_array, start=[]):
[flatten(x, start) if type(x) == list else start.append(x) for x in nested_array]
return start
# test
given_array = [[1, 2, [3]], 4]
print(flatten(given_array))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment