June 2017
Beginner
352 pages
8h 39m
English
As with lists dictionary copying is shallow by default, copying only the references to the key and value objects, not the objects themselves. There are two means of copying a dictionary, of which we most commonly see the second. The first technique is to use the copy() method:
>>> d = dict(goldenrod=0xDAA520, indigo=0x4B0082, seashell=0xFFF5EE)>>> e = d.copy()>>> e{'indigo': 4915330, 'goldenrod': 14329120, 'seashell': 16774638}
The second is simply to pass an existing dictionary to the dict() constructor:
>>> f = dict(e)>>> f{'indigo': 4915330, 'seashell': 16774638, 'goldenrod': 14329120}
Read now
Unlock full access