Question: (Shallow vs. Deep Copy) In this chapter, we discussed shallowvs. deep copies of arrays. Pythons built-in list and dictionarytypes have copy methods that perform shallow
(Shallow vs. Deep Copy) In this chapter, we discussed shallowvs. deep copies of arrays. Python’s built-in list and dictionarytypes have copy methods that perform shallow copies. Using thefollowing dictionary dictionary = {'Sophia': [97, 88]} demonstratethat a dictionary’s copy method indeed performs a shallow copy. Todo so, call copy to make the shallow copy, modify the list storedin the original dictionary, then display both dictionaries to seethat they have the same contents. Next, use the copy module’sdeepcopy function to create a deep copy of the dictionary. Modifythe list stored in the original dictionary, then display bothdictionaries to prove that each has its own data
Use Python
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
