strange behaviour with remove

Panard panard at inzenet.org
Sat Jun 19 06:41:58 EDT 2004


Hi!

Can anyone explain this to me :
$ cat test.py
l = [ 1, 2, 3 ]
d = { 'list' : l }

for x in l :
        print "rm", x
        d[ 'list' ].remove( x )
        print "l =", l

print d

$ python test.py
rm 1
l = [2, 3]
rm 3
l = [2]
{'list': [2]}


Why 2 isn't removed ? and why l is changing during the loop ??
Am I missing something ?

My python is 2.3.4

Thanks

-- 
Panard



More information about the Python-list mailing list