[Python-ideas] Another attempt at a sum() alternative: the concatenation protocol

Joshua Landau joshua at landau.ws
Tue Jul 16 17:25:50 CEST 2013


On 16 July 2013 14:01, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On 16 July 2013 22:28, Joshua Landau <joshua at landau.ws> wrote:
>> On 16 July 2013 11:21, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
>>> On 16 July 2013 07:50, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>>
>>> If people are using sum() to concatenate lists then this should be
>>> taken not as evidence that a new solution needs to be found but as
>>> evidence that chain is not sufficiently well-known. The obvious
>>> solution to that is not to implement a new protocol but to make the
>>> existing solution more well known i.e. move chain.from_iterable to
>>> builtins and rename it (the obvious choice being concat).
>>
>> You could wait for PEP 448, which will let you use [*sublist for
>> sublist in list_to_be_flattened].
>
> Ah, true, I forgot about that. Too many interesting things going on
> for me to keep track of everything :)
...
> That's pretty cool. It also means I can go back to happily ignoring
> the sum threads :)

:D

> P.S. Something about this should probably be added to the rationale
> section of PEP 448

There is: "The addition of unpacking to comprehensions is a logical
extension. It's usage will primarily be a neat replacement for [i for
j in 2D_list for i in j], as the more readable [*l for l in 2D_list].
Other uses are possible, but expected to occur rarely."

If you require more than that, I'll be happy to add something in.


More information about the Python-ideas mailing list