Is this a refrence issue?
Carl J. Van Arsdall
cvanarsdall at mvista.com
Wed Dec 28 17:40:45 EST 2005
KraftDiner wrote:
> I understand that everything in python is a refrence....
>
> I have a small problem..
>
> I have a list and want to make a copy of it and add an element to the
> end of the new list,
> but keep the original intact....
>
> so:
> tmp = myList
>
tmp = myList is a shallow copy
> tmp.append(something)
> print tmp, myList
>
> should be different...
>
Therefore it shouldn't be different.
What you could do is make a second list
tmp = []
And then use the extend method:
tmp.extend(myList)
tmp.append(someEntry)
This would give you what you want, and there's more than one way to do this.
-carl
--
Carl J. Van Arsdall
cvanarsdall at mvista.com
Build and Release
MontaVista Software
More information about the Python-list
mailing list