Generator Comprehensions

Raymond Hettinger othello at javanet.com
Mon Jan 28 21:29:46 EST 2002


Wild idea of the day:  Extend the syntax for list comprehensions
to have an optional 'yield' to create a generator rather than a list.

sizegen = [ yield (len(line),line) for line in file.readline() ]
print 'Line 1:', g.next()
print 'Line 2:', g.next()


Raymond Hettinger





More information about the Python-list mailing list