i=2; lst=[i**=2 while i<1000]
Bengt Richter
bokr at oz.net
Tue Dec 6 11:50:48 EST 2005
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]
Regards,
Bengt Richter
More information about the Python-list
mailing list