Syntax: pointers versus value

Danny Castonguay castong at mathstat.concordia.ca
Wed Jul 30 12:46:43 EDT 2003


Simple question but I can't find the answer.  Using an example:

listA = [1 ,2]
listB = listA
listB.append(3)
#listA now is [1,2,3]

I want to avoid listA's value to change. Clearly, "listB = listA" 
creates the problem.  listB and listA become two pointers to the same 
object.  How then, do I duplicate the two objects; ie make a copy of the 
  object that listA is pointing to and have listB point to that object.

I'm new to python and I love it.

Thank you,





More information about the Python-list mailing list