Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Flatten a List by sshiori
def flat_list(array):
result = []
for num in array:
if type(num) == int:
result.append(num)
else:
for n in flat_list(num):
result.append(n)
return result
if __name__ == '__main__':
assert flat_list([1, 2, 3]) == [1, 2, 3], "First"
assert flat_list([1, [2, 2, 2], 4]) == [1, 2, 2, 2, 4], "Second"
assert flat_list([[[2]], [4, [5, 6, [6], 6, 6, 6], 7]]) == [2, 4, 5, 6, 6, 6, 6, 6, 7], "Third"
assert flat_list([-1, [1, [-2], 1], -1]) == [-1, 1, -2, 1, -1], "Four"
print('Done! Check it')
Oct. 14, 2019