list problem 4 newbie

vaibhav vaikings at gmail.com
Mon Jun 26 02:48:40 EDT 2006


Hi,
if u check the id's of a and b lists and also its elements, you will
obeserve that the id's of a and b have changed  but id's of their
elements have not changed.
 If you make a deep copy of the list a and then make your changes in
that list, it shud work.  this can be done using the copy module.

hope that helps,
vaibhav

>>> id(a)
-1208622388
>>> id(b)
-1208622324

>>> for el in a:
...     print id(el)
...
-1208622836
-1208622708
-1208622772
-1208622420

>>> for el in b:
...     print id(el)
...
-1208622836
-1208622708
-1208622772
-1208622420

>>> import copy
>>> c = copy.deepcopy(a)
>>> id(c)
-1208464564

>>> for el in c:
...     print id(el)
...
-1208465172
-1208464276
-1208464180
-1208463988




More information about the Python-list mailing list