i=2; lst=[i**=2 while i<1000]

bonono at gmail.com bonono at gmail.com
Tue Dec 6 11:55:28 EST 2005


Bengt Richter wrote:
> On 6 Dec 2005 07:41:45 -0800, bonono at gmail.com wrote:
> >
> >If one really wants a very messy one-liner, it is possible
> >
> >import operator
> >x=3D[2]
> >lst=3Dlist(((operator.setitem(x,0,x[0]**2),x[0])[1] for _ in
> >xrange(10000000) if x[0] < 1000 or iter([]).next()))
> >
> Or
>  >>> list(iter(lambda b=[2]:b.append(b[0]**2) or b[0]<1000 and b.pop(0) or None, None))
>  [2, 4, 16, 256]
> 
out of curiosity, what stops the iterator ?




More information about the Python-list mailing list