concept copy in category python

appears as: copy, copies
Get Programming: Learn to code with Python

This is an excerpt from Manning's book Get Programming: Learn to code with Python.

You can think of a list as a structure that maps an integer (index 0, 1, 2, 3 ...) to an object; a list can be indexed only by an integer. A dictionary is a data structure that can map any object, not just an integer, to any other object; indexing using any object is more useful in situations when you have pairs of data. Like lists, dictionaries are mutable so that when you make a change to a dictionary object, the object itself changes without having to make a copy of it.

  • Make copies of mutable objects (lists and dictionaries)
  • Figure 28.3. In the panel on the left, making a copy of the object ["monet", "picasso"] makes a new object with the same elements. In the panel on the right, you can mutate one object without interfering with the other object.

    Instead of making a copy of the list and then sorting the copy, Python has a function that allows you to do it in one line. The following command shows a function that returns a sorted version of a list and stores it in another list: