I know that Slicing lists does not generate copies of the objects in the list; it just copies the references to them.
But if that\'s the case, then why doesn\'t this wor
Slicing a list
returns a new shallowly-copied list
object. While you are correct that it does not deep-copy the original list's items, the result is a brand new list
distinct from the original.
See the Python 3 tutorial:
All slice operations return a new list containing the requested elements. This means that the following slice returns a shallow copy of the list:
>>> squares = [1, 4, 9, 16, 25] >>> squares[:] [1, 4, 9, 16, 25]
Consider
>>> squares[:] is squares
False