Hi, Jason,

On Nov 4, 2008, at 14:38 , Jason Bandlow wrote:
> Hi Stan,
>
> I think I saw one question you asked that hasn't been answered yet:
>
> Stan Schymanski wrote:
>
> <snip>
>>
>> If I construct a list out of two other lists, I usually don't
>> expect the original lists to change if I manipulate the resulting
>> list. How can I break such links?
> <snip>
>
> The way I usually do this is:
> sage: L = [1, 2, 3]
> sage: LL = L[:]
>
> This makes LL a copy of L instead of reference to it.  As such, I can
> manipulate the two completely independently.

Just following up on your comments.  This does not do a "deep copy",  
so just the "top level" of the list is copied:

sage: L=[[1,2,3],[4,5,6],[7,8,9]]
sage: LL=L[:]
sage: L[1][1]=17
sage: L
  [[1, 2, 3], [4, 17, 6], [7, 8, 9]]
sage: LL
  [[1, 2, 3], [4, 17, 6], [7, 8, 9]]
sage: LL[0]=1
sage: LL
  [1, [4, 17, 6], [7, 8, 9]]
sage: L
  [[1, 2, 3], [4, 17, 6], [7, 8, 9]]


Justin

--
Justin C. Walker, Curmudgeon at Large
Director
Institute for the Enhancement of the Director's income
-----------
--
They said it couldn't be done, but sometimes,
it doesn't work out that way.
   - Casey Stengel
--




--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to