On Thu, Jun 17, 2021 at 3:27 PM David Mertz
On Thu, Jun 17, 2021, 1:14 AM Christopher Barker
I'm sympathetic to raising an exception on `sum(list_of_lists)` similar to `sum(list_of_strings)`. But what exactly is the recommended substitute? We have this:
list(chain.from_iterable(list_of_lists))
If you read the BPO the OP linked, that was a suggested patch to optimize sum(list_of_lists) -- I'm not sure that's such a bad idea after all.
The proposal was to drop in .__iadd__() for .__add__(), wasn't it? As a heavy NumPy user, you know those sometimes have different semantics.
I actually showed that in my 7 year old talk as one argument against it.
More-itertools has flatten(): https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.flat.... That seems better than a method specific to lists.
... which is built on top of chain.from_iterable. :) ChrisA