Last active
March 15, 2017 13:38
-
-
Save ImageAsInput/e0a05239e39241dac7827e10b8d03a23 to your computer and use it in GitHub Desktop.
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
#Input Variable | |
nestedX = [[[[[1, 2, [[[3]]]], 4]]]] | |
#Recursive function written quickly. | |
def flatten(nX): | |
flatX = [] | |
for x in nX: | |
if isinstance(x,int): | |
flatX += [x] | |
else: | |
flatX += flatten(x) | |
return flatX | |
#print the output | |
print flatten(nestedX) | |
#Funny and ugly way to do it :P :P (list function needed for python 3.x not 2.x). Never do it in REAL LIFE! | |
#print list(map(int,str(nestedX).replace('[','').replace(']','').split(','))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment