list traversal and remove
- From: "digisatori@xxxxxxxxx" <digisatori@xxxxxxxxx>
- Date: Wed, 30 Jan 2008 23:49:46 -0800 (PST)
I supposed the below code will print seven 2 and generate the list li
without 2.
Strangely it only print four 2. If you change the number of 2 in the
list, the results are all beyond expectation.
I know the other way to achieve the expected goal, but why this is
happening? Could somebody enlight me?
li= [2,2,2,2,2,2,2,3,4,5,6,7,8,9]
for x in li:
if x == 2:
print x
li.remove(x)
.
- Follow-Ups:
- Re: list traversal and remove
- From: digisatori@xxxxxxxxx
- Re: list traversal and remove
- From: Steven D'Aprano
- Re: list traversal and remove
- From: Arnaud Delobelle
- Re: list traversal and remove
- Prev by Date: Re: Dictionary Keys question
- Next by Date: Re: Sine Wave Curve Fit Question
- Previous by thread: RE: Has Anyone Worked with Gene Expression Programming???????????????????????????
- Next by thread: Re: list traversal and remove
- Index(es):