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

Steven Bethard steven.bethard at gmail.com
Tue Dec 6 10:39:39 EST 2005


Daniel Schüle wrote:
> I am wondering if there were proposals or previous disscussions in this 
> NG considering using 'while' in comprehension lists
> 
> # pseudo code
> i=2
> lst=[i**=2 while i<1000]

I haven't had much need for anything like this.  Can't you rewrite with 
a list comprehension something like::

 >>> [4**(2**i) for i in xrange(math.log(1000, 4))]
[4, 16, 256, 65536]

?

STeVe



More information about the Python-list mailing list