On 12/28/05, Carl J. Van Arsdall <[EMAIL PROTECTED]> wrote: > 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. >
Such as from the python docs.. import copy x = copy.copy(y) # make a shallow copy of y x = copy.deepcopy(y) # make a deep copy of y > -carl > > -- > > Carl J. Van Arsdall > [EMAIL PROTECTED] > Build and Release > MontaVista Software > > -- > http://mail.python.org/mailman/listinfo/python-list > -- James Tanis [EMAIL PROTECTED] http://pycoder.org -- http://mail.python.org/mailman/listinfo/python-list
