Re: Copy List

2007-07-19 Thread Jason
On Jul 19, 10:21 am, Falcolas <[EMAIL PROTECTED]> wrote: > On Jul 18, 6:56 am, "Rustom Mody" <[EMAIL PROTECTED]> wrote: > > > This is shallow copy > > If you want deep copy then > > from copy import deepcopy > > What will a "deep copy" of a list give you that using the slice > notation will not? W

Re: Copy List

2007-07-19 Thread James Matthews
A slice still has some references to the old objects a deep copy is a totally new object! On 19 Jul 2007 17:04:00 GMT, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: On Thu, 19 Jul 2007 09:21:54 -0700, Falcolas wrote: > On Jul 18, 6:56 am, "Rustom Mody" <[EMAIL PROTECTED]> wrote: >> This

Re: Copy List

2007-07-19 Thread Marc 'BlackJack' Rintsch
On Thu, 19 Jul 2007 09:21:54 -0700, Falcolas wrote: > On Jul 18, 6:56 am, "Rustom Mody" <[EMAIL PROTECTED]> wrote: >> This is shallow copy >> If you want deep copy then >> from copy import deepcopy > > What will a "deep copy" of a list give you that using the slice > notation will not? Well, a d

Re: Copy List

2007-07-19 Thread Falcolas
On Jul 18, 6:56 am, "Rustom Mody" <[EMAIL PROTECTED]> wrote: > This is shallow copy > If you want deep copy then > from copy import deepcopy What will a "deep copy" of a list give you that using the slice notation will not? -- http://mail.python.org/mailman/listinfo/python-list

Re: Copy List

2007-07-18 Thread Lawrence Oluyede
Joe Riopel <[EMAIL PROTECTED]> wrote: > I am pretty new to python but this works: > > >>> list_one = [0,1,2,3,4,5,6,7,8,9] > >>> list_two = [i for i in list_one] > >>> print list_two > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >> list_two = list_one[:] or >> list_two = list(list_one) are better :D --

Re: Copy List

2007-07-18 Thread Rustom Mody
The standard idiom (I guess) is to use the slice >>> a=[1,2,3,4] >>> b=a >>> b is a True >>> b [1, 2, 3, 4] >>> c=a[:] >>> c is a False >>> c [1, 2, 3, 4] This is shallow copy If you want deep copy then from copy import deepcopy -- http://mail.python.org/mailman/listinfo/python-list

Re: Copy List

2007-07-18 Thread Joe Riopel
I forgot to mention that you can go here for a little more of an explanation: http://diveintopython.org/native_data_types/mapping_lists.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Copy List

2007-07-18 Thread Joe Riopel
On 7/18/07, Robert Rawlins - Think Blue <[EMAIL PROTECTED]> wrote: > What's the best way to create a copy of a list? I am pretty new to python but this works: >>> list_one = [0,1,2,3,4,5,6,7,8,9] >>> list_two = [i for i in list_one] >>> print list_two [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> -- http:/

Re: Copy List

2007-07-18 Thread Tim Williams
On 18/07/07, Robert Rawlins - Think Blue <[EMAIL PROTECTED]> wrote: > > 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: > listB =

Copy List

2007-07-18 Thread Robert Rawlins - Think Blue
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: __Init__(self): Self.myList = [] regenerateList