[Python-Dev] Re: "groupby" iterator

Greg Ball gball at cfa.harvard.edu
Wed Dec 3 11:18:21 EST 2003

Would it work to generalise generator expressions in the following way:

(x[1] for x) == lambda x:x[1]
(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

i.e. an anonymous block notation, with early binding semantics.  It could
work as a lambda replacement. But no-argument lambdas would require some
extra ugliness.

(1 for)  == lambda:1 #    yuck!
(1 for ()) == lambda:1 # better?

And should this be allowed?

((a,b) for a in l for b,l) == lambda b,l: ((a,b) for a in l)

Greg Ball

More information about the Python-Dev mailing list