Skip to content

Instantly share code, notes, and snippets.

@wilsotc
Created March 12, 2019 23:57
Show Gist options
  • Save wilsotc/88f85833f5d29f56fc71b1b674521d08 to your computer and use it in GitHub Desktop.
Save wilsotc/88f85833f5d29f56fc71b1b674521d08 to your computer and use it in GitHub Desktop.
flatten array function
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