[BangPypers] How for and list.remove() works

Kushal Das kushaldas at gmail.com
Wed Jul 9 18:52:14 CEST 2008


On Wednesday 09 July 2008 09:26:09 pm Anand Chitipothu wrote:
> It never iterated over the second the 12. When x=12 for the last time,
> there was still a 12 at the begining of the list. (try printing the
> list also for every iteration).
>
> It internally maintains an index for iteration. If you have a list
> with values [x, y, z] and if you remove x in the first iteration, the
> list becomes  [y, z]. In the next iteration it returns the second
> element, which is z. so y never  gets a chance to be part of the
> iteration.
So that in-memory is the prime accused here.

Kushal
-- 
Fedora Ambassador, India
http://kushaldas.in
http://dgplug.org (Linux User Group of Durgapur)



More information about the BangPypers mailing list