Bug?

Steve Holden sholden at holdenweb.com
Wed Aug 1 00:11:03 EDT 2001


As a general rule it's a very bad idea to change a list you're iterating
over with for.

a-list-by-any-other-name-can-still-be-changed-ly y'rs  - steve
--
http://www.holdenweb.com/


"Ricardo Correia" <google.com at wizemail1.cjb.net> wrote in message
news:4835e825.0107241639.bbf438e at posting.google.com...
> Hi
>
> ---------------------------------------------------
> mainlist = [1, 2, 3, 4, 5]
> copy = mainlist
>
> for item in copy:
>  print item,
>  mainlist.remove(item)
> ---------------------------------------------------
>
> Shouldn't this produce '1 2 3 4 5'?
>
> I only get '1 3 5' and unfortunately because of this my program doesn't
work.
>
> I'm using python 2.0 (the one that comes with Mandrake 8.0)
>
> Thanks
>
> Ricardo Correia





More information about the Python-list mailing list