Created
March 12, 2019 23:57
-
-
Save wilsotc/88f85833f5d29f56fc71b1b674521d08 to your computer and use it in GitHub Desktop.
flatten array function
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( arr, arr2 ): | |
for ele in enumerate( arr ): | |
if type(ele[1]) is list: | |
flatten (ele[1], arr2) | |
else: | |
z.append(ele[1]) | |
y = [2,[3,[4,9]],4,[5,6]] | |
z = [] | |
flatten(y,z) | |
print (y) | |
print "becomes" | |
print (z) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment