On Thu, Jun 17, 2021 at 3:27 PM David Mertz <me...@gnosis.cx> wrote: > > 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.flatten. > That seems better than a method specific to lists.
... which is built on top of chain.from_iterable. :) ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/JYWYASNLXEHH7QG2XVTI37UBO635CDE7/ Code of Conduct: http://python.org/psf/codeofconduct/