17.06.21 06:03, David Mertz пише:
> 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))
>
> Which is pretty nice, and what I'd probably do, but it DOES require
> importing from itertools to use it. That feels like a drawback, at
> least a minor one.
And it is equivalent to pure Python code
[x for chunk in list_of_lists for x in chunk]
It has linear complexity and is only by a constant factor slower because
it iterates loops in bytecode instead of the C code. It would be
possible to make the compiler recognizing such pattern and generating
more efficient bytecode (LIST_EXTEND instead of an internal loop with
LIST_APPEND), but I am not sure that this case is common enough to
complicate the compiler.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/TK3QJ6HNUV6IN5C6ZVG5PIWRXZ36BXO2/
Code of Conduct: http://python.org/psf/codeofconduct/