i=2; lst=[i**=2 while i<1000]
Daniel Schüle
uval at rz.uni-karlsruhe.de
Tue Dec 6 09:27:21 EST 2005
hi,
[...]
>># 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?
unless I am missing something obvious, I can not see why the loop should
not terminate
sure pseudo code is not executable but the other one works
while tests the boolean expression first then decides whether to execute
the body or not, in particular no next-iterator is involved(??)
as it would be in
lst=range(5)
for i in lst:
del lst[0]
Regards, Daniel
More information about the Python-list
mailing list