
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, copied_list = original_list[:].""" Surely this is a typo? To my understanding, copied_list = original_list[:] gives you a clean copy (slicing returns a new object....) Can this be updated? Or someone explain to me why it's correct? Cheers Example:
t = [1, 2, 3] y = t u = t[:] y[1] = "rawr" t [1, 'rawr', 3] u [1, 2, 3]

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, copied_list = original_list[:]."""
Surely this is a typo? To my understanding, copied_list = original_list[:] 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

On Fri, Jun 25, 2010 at 11:04 AM, Steve Holden <steve@holdenweb.com> wrote:
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, copied_list = original_list[:]."""
Surely this is a typo? To my understanding, copied_list = original_list[:] 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.
My apologies guys, I see now. I will see if I can think of a less ambiguous way to word this and submit a bug. Thankyou!

On Thu, Jun 24, 2010 at 8:51 PM, Rich Healey <healey.rich@gmail.com> 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, copied_list = original_list[:]."""
Surely this is a typo? To my understanding, copied_list = original_list[:] gives you a clean copy (slicing returns a new object....)
If you read the doc excerpt carefully, you will realize that it says the same thing. I agree that the language can be improved, though. There is no need to bring in assignment to explain that a[:] makes a copy of list a. Please create a documentation issue at http://bugs.python.org . If you can suggest a better formulation, it is likely to be accepted.

On Thu, Jun 24, 2010 at 09:05:09PM -0400, Alexander Belopolsky wrote:
On Thu, Jun 24, 2010 at 8:51 PM, Rich Healey <healey.rich@gmail.com> 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, copied_list = original_list[:]."""
Surely this is a typo? To my understanding, copied_list = original_list[:] gives you a clean copy (slicing returns a new object....)
the same thing. I agree that the language can be improved, though. There is no need to bring in assignment to explain that a[:] makes a copy of list a. Please create a documentation issue at
Better still, add your doc change suggestion (possible explanation) to this issue: http://bugs.python.org/issue9021 -- Senthil

On 6/24/2010 8:51 PM, Rich Healey wrote:
Discussion of the wording of current docs should go to python-list. Py-dev is for development of future Python. -- Terry Jan Reedy

Am 25.06.2010 18:57, schrieb Terry Reedy:
On 6/24/2010 8:51 PM, Rich Healey wrote:
Discussion of the wording of current docs should go to python-list. Py-dev is for development of future Python.
No no no. Mis-worded documentation is a bug, just like any other bug, and deserves being discussed here. Furthermore, a sufficient condition for mis-wording is if a user read it in full, and still managed to misunderstand (as happened here). Regards, Martin

Martin v. Löwis wrote:
Am 25.06.2010 18:57, schrieb Terry Reedy:
On 6/24/2010 8:51 PM, Rich Healey wrote:
http://docs.python.org/library/copy.html Discussion of the wording of current docs should go to python-list. Py-dev is for development of future Python.
No no no. [...]
It isn't always easy to tell, but I think Martin meant "no". regards Steve -- 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
participants (6)
-
"Martin v. Löwis"
-
Alexander Belopolsky
-
Rich Healey
-
Senthil Kumaran
-
Steve Holden
-
Terry Reedy