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 tony-aycc
def flat_list(array):
for item in array:
try:
yield from flat_list(item)
except TypeError:
yield item
print(list(flat_list([1, 2, 3])))
print(list(flat_list([1, [2, 2, 2], 4])))
print(list(flat_list([[[2]], [4, [5, 6, [6], 6, 6, 6], 7]])))
print(list(flat_list([-1, [1, [-2], 1], -1])))
Feb. 12, 2020
Comments: