News for hackers. Stuff that matters.
Re:Why it’s hard for programmers to write a program to flatt... by Latty on Friday February 24, 2017 @11:46AM (#13725255)
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...

There are no comments on this comment yet.