[Python-Dev] docs - Copy (original) (raw)
Steve Holden steve at holdenweb.com
Fri Jun 25 03:04:03 CEST 2010
- Previous message: [Python-Dev] docs - Copy
- Next message: [Python-Dev] docs - Copy
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Rich Healey wrote:
http://docs.python.org/library/copy.html
Just near the bottom it reads: """Shallow copies of dictionaries can be made using dict.copy(), and of lists by assigning a slice of the entire list, for example, copiedlist = originallist[:]."""
Surely this is a typo? To my understanding, copiedlist = originallist[:] gives you a clean copy (slicing returns a new object....) Yes, but it's a shallow copy: the new object references exactly the same objects as the original list (not copies of those objects). A deep copy would need to copy any referenced lists, and so on.
Can this be updated? Or someone explain to me why it's correct? It sounds correct to me.
regards Steve
Cheers
Example:
t = [1, 2, 3] y = t u = t[:] y[1] = "rawr" t [1, 'rawr', 3] u [1, 2, 3]
-- Steve Holden +1 571 484 6266 +1 800 494 3119 See Python Video! http://python.mirocommunity.org/ Holden Web LLC http://www.holdenweb.com/ UPCOMING EVENTS: http://holdenweb.eventbrite.com/ "All I want for my birthday is another birthday" - Ian Dury, 1942-2000
- Previous message: [Python-Dev] docs - Copy
- Next message: [Python-Dev] docs - Copy
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]