Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
With repr() solution in Clear category for Flatten a List by akamus
def flat_list(array):
representation = repr(array).replace('[', '').replace(']', '').split(', ')
return [int(i) for i in representation if i != '']
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"
assert flat_list([[[[[[[[[]]]]]]]]]) == []
assert flat_list([-1,[1,[-2,[3],[[5],[10,-11],[1,100,[-1000,[5000]]],[20,-10,[[[]]]]]]]]) == [-1,1,-2,3,5,10,-11,1,100,-1000,5000,20,-10]
assert flat_list([[[[[[[[[4294967295]]]]]]]]]) == [4294967295]
print('Done! Check it')
May 31, 2020