delay and force in Python
Nick Coghlan
ncoghlan at iinet.net.au
Wed Jan 26 02:30:42 EST 2005
Bengt Richter wrote:
> You can bail out of a generator expression with a raise-StopIteration expression spelled iter([]).next() ;-)
>
> >>> list(show(x) for x in xrange(20) if x<8 or iter([]).next() or True)
> 0 1 2 3 4 5 6 7
> [0, 1, 2, 3, 4, 5, 6, 7]
This is both neat and incredibly arcane at the same time :)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-list
mailing list