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

Duncan Booth duncan.booth at invalid.invalid
Tue Dec 6 09:27:34 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]
> 
> of course this could be easily rewritten into
> i=2
> lst=[]
> while i<1000:
>      i**=2
>      lst.append(i)
> 

Neither of these loops would terminate until memory is exhausted. Do you 
have a use case for a 'while' in a list comprehension which would 
terminate?



More information about the Python-list mailing list