Came across this example after lots of searching.
nested_lists = [[1, 2], [[3, 4], [5, 6], [[7, 8], [9, 10], [[11, [12, 13]]]]]]
flattened = lambda *n: (e for a in n for e in (flattened(*a) if isinstance(a, (tuple, list)) else (a,)))
print(list(flattened(nested_lists)))
It works but is ugly and hard to follow but I like that it was done in 1 line of code.
Is there a neater way while still keeping it as concise.
Thanks
To make ts clear the code should give the result [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]