Copy List

Robert Rawlins - Think Blue robert.rawlins at
Wed Jul 18 13:58:51 CEST 2007

Hello Guys,


What's the best way to create a copy of a list? I've seen several method and
I'm not sure what to use. This will be in a class and one method creates a
list which I then want to move to the self scope, like so:



                Self.myList = []




                newList = []


                for somthing in somthing:



                self.Mylist = newList.copy()


See, The iteration and rebuilding of the list could be quite slow, during
which time the application could be reading from the self.mylist variable so
i think simply doing this:




                self.myList = []


                for somthing in somthing:



Might cause a few inconsistencies in the list if it's being read from whilst
I'm appending too it, so I'm guessing that the top example is the best
method, I'm just looking for the best way to copy() that list into the self
scope, should i be using copy(), deepcopy() or simply self.mylist = newlist?


Thanks guys,




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list