Generator Comprehensions
Raymond Hettinger
othello at javanet.com
Tue Jan 29 12:15:05 EST 2002
"Oren Tirosh" <oren-py-l at hishome.net> wrote in message
news:mailman.1012301512.25481.python-list at python.org...
> > sizegen = [ yield (len(line),line) for line in file.readline() ]
>
> I like it. Reusing the yield keyword is a very elegant solution.
>
> One problem with this syntax is that there is no justification for the use
> of square brackets - the result isn't a list. It looks like it can work
> just fine without them.
I agree. The square brackets say 'list' which they mean 'generator'
Raymond Hettinger
More information about the Python-list
mailing list