Last active
January 28, 2019 03:40
-
-
Save computerex/493eed0c43ad6f42349449dfe3338820 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 = [[1,2,[3]],4, [5], [[[[6],7], 8]]] | |
def flatten(input, flattened): | |
for e in input: | |
if type(e) == list: | |
flatten(e, flattened) | |
else: | |
flattened.append(e) | |
return flattened | |
print("input: " + str(input)) | |
output = flatten(input, []) | |
print("output: " + str(output)) | |
fail = False | |
for e in output: | |
if type(e) == list: | |
print("fail: array not flattened") | |
fail = True | |
break | |
if fail: | |
print("Testing failed") | |
else: | |
print("All tests passed") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment