[Python-Dev] Re: "groupby" iterator
pedronis at bluewin.ch
Thu Dec 4 08:09:43 EST 2003
At 16:22 04.12.2003 +1300, Greg Ewing wrote:
>Greg Ball <gball at cfa.harvard.edu>:
> > (x for x) == lambda x:x
> > (x.score for x) == lambda x: x.score
> > (x+y for x,y) == lambda x,y: x+y
> > (len(x) for x) == lambda x,len=len: len(x) # roughly equivalent
>Interesting idea, but it reads a bit strangely.
>Maybe this would work better with a different keyword...
> x given x
> x.score given x
> x+y given x,y
> len(x) given x
> stuff = groupby((x for x in seq), key = (x.score given x))
on the plus side it nicely parallels generator expressions and the keyword
makes lookup in the docs easy. On the minus side is maybe verbose.
On the other hand non-keyword notations risk to be too cryptic: some
stuff = groupby((x for x in seq), key = (x.score\x))
# this would require the lexer to distinguish \ as line continuation vs
# it would probably still be read as "x.score given x"
stuff = groupby((x for x in seq), key = (x-->x.score)) # --> would be a
More information about the Python-Dev