how to explain such codes, python's bug or mine?

MaHahaXixi enjoy_linux at hotmail.com
Wed Apr 13 07:41:25 EDT 2005


yes. i think it does so.
it take me the whole afternoon to find out the bug (mine)
i change:
for i  in range(len(j) -1, -1, -1):
   d = j[i]
   if d <= 10:
        j.remove(d)

the real code is not so simple,so j[11:] will not work for me.
but, i think phthon could found that i remove the current element,  why it
does not move the pointer automatically?
for python, i am a newbie, but i did not found the warning of such usage
from the python tutorial

<ajikoe at gmail.com> wrote in message
news:1113386913.961445.165950 at z14g2000cwz.googlegroups.com...
> Hi,
>
> it is not python bug.
> You refer the list j and remove the element in the same time, that is
> the problem. Python dinamicaly goes to the next element with the same
> index but apply it in the new list.
>
> use this code instead:
>   j = range(20)
>   print j
>   L = [x for x in j if x > 10]
>   print L
>
> Sincerely Yours,
> Pujo
>





More information about the Python-list mailing list