Jan-26-2018, 12:13 AM
I want to break Python 2 support bye using
yield from
.def flatten(seq): for item in seq: if isinstance(item, list): yield from flatten(item) else: yield item lst = [[[2], [4, 1, 3]], [5, 7], 1, 10, [[[5, 5, 5], [4, 4, 4]]]] print(list(flatten(lst)))
Output:[2, 4, 1, 3, 5, 7, 1, 10, 5, 5, 5, 4, 4, 4]