Created
September 27, 2018 22:52
-
-
Save debuggerpk/40ab93ec18e790e71368041c517551f5 to your computer and use it in GitHub Desktop.
Flattens a nested array
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(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