[Python-Dev] Re: comprehension abbreviation (was: Adding any() and all()) (original) (raw)

Steve Holden steve at holdenweb.com
Tue Mar 29 08:28:19 CEST 2005


Jim Jewett wrote:

Gareth McCaughan wrote:

Some bit of my brain is convinced that [x in stuff if condition] is the Right Syntax and keeps making me type it even though I know it doesn't work. (and I agree with Gareth) On Monday 2005-03-14 12:42, Eric Nieuwland wrote: The full syntax is: [ f(x) for x in seq if pred(x) ] being allowed to write 'x' instead of 'identity(x)' is already a shortcut, just as dropping the conditional part. I think this is the heart of the disagreement. Mentally, I'm not collecting some function of x (which happens to be identity). I am filtering an existing set. Being able to collect f(x) instead is just a useful but hackish shortcut. Have it your own way, but if you happen to need a list of transformed elements of a filtered list (and that isn't an uncommon requirement) then the idea of selecting the set members and then transforming the copies as a separate step seems a little ... unnecessary.

Having to write

 [x for x in seq]

to produce a copy of a list doesn't seem that outrageous to me, and I don't find the predicate-less case of your proposal that convincing:

 [x in seq]

seems somehow too terse.

[...]

regards Steve

Steve Holden +1 703 861 4237 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/



More information about the Python-Dev mailing list