[Python-Dev] comprehension abbreviation (was: Adding any() and all()) (original) (raw)
Gareth McCaughan gmccaughan at synaptics-uk.com
Mon Mar 14 14:23:59 CET 2005
- Previous message: [Python-Dev] comprehension abbreviation (was: Adding any() and all())
- Next message: [Python-Dev] comprehension abbreviation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Monday 2005-03-14 12:42, Eric Nieuwland wrote:
Gareth McCaughan wrote:
> I'd like it, and my reason isn't "just to save typing". > There are two reasons. > > 1 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. > > 2 Seeing [x for x in stuff if condition] triggers my internal > duplicated-stuff alarm, and it's distracting, in the same sort > of way as it's distracting in C or C++ seeing 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. Remember we're doing set theory stuff here. IMHO we should follow its notation conventions as much as we can.
I'm well aware of what the full syntax is; being allowed to write "x" instead of "identity(x)" is not a "shortcut" but a perfectly straightforward unexceptional instance of the usual syntax; list comprehensions already have neither the syntax nor the semantics of set-theorists' comprehensions; and in fact no set theorist would be at all troubled by seeing
{ x in S : predicate(x) }which is the nearest equivalent in mathematical notation for the abbreviated comprehension expressions being discussed.
Other than that, I quite agree :-).
-- g
- Previous message: [Python-Dev] comprehension abbreviation (was: Adding any() and all())
- Next message: [Python-Dev] comprehension abbreviation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]