2 ms·
As others have pointed out, that only flattens one level (which, admittedly, is a much more useful thing most of the time - arbitrarily deeply nested structures
by Latty 10y ago
As others have pointed out, that only flattens one level (which, admittedly, is a much more useful thing most of the time - arbitrarily deeply nested structures are relatively rare).
If you do want to do this, the better method is:
itertools.chain.from_iterable()
That has the advantage of being lazy, as opposed to a list comprehension, and has the potential to be more optimised. It also doesn't rely on the somewhat obscure and relatively hard to read nested list comprehension syntax.
Docs: https://docs.python.org/3.6/library/itertools.html#itertools.chain.from_iterable https://docs.python.org/3.6/library/itertools.html#itertools...