[Python-ideas] Fwd: Fwd: unpacking generalisations for list comprehension

Random832 random832 at fastmail.com
Sat Oct 15 13:17:21 EDT 2016


On Sat, Oct 15, 2016, at 06:38, Steven D'Aprano wrote:
> > Replacing it _with the items_ is not the same thing as replacing it
> > _with a sequence containing the items_, 
> 
> I don't think I ever used the phrasing "a sequence containing the 
> items". I think that's *your* phrase, not mine.

It's not your phrasing, it's the actual semantic content of your claim
that it would have to wrap them in a tuple.

> The core developers have made it absolutely clear that changing the 
> fundamental equivalence of list comps as syntactic sugar for:
> 
>     result = []
>     for t in iterable:
>         result.append(t)
> 
> 
> is NOT NEGOTIABLE.

I've never heard of this. It certainly never came up in this discussion.
And it was negotiable just fine when they got rid of the leaked loop
variable.

> (That is much to my disappointment -- I would love to 
> introduce a "while" version of list comps to match the "if" version, but 
> that's not an option.)
> 
> So regardless of whether it is a fiction or an absolute loop, Python's 
> list comprehensions are categorically limited to behave equivalently to 
> the loop above (modulo scope, temporary variables, etc). 

See, there it is. Why are *those* things that are allowed to be
differences, but this (which could be imagined as "result += [t]" if you
_really_ need a single statement where the left-hand clause is
substituted in, or otherwise) is not?


More information about the Python-ideas mailing list