160. Deep Copy vs Shallow Copy
import copy
# Original list with nested list
original_list = [1, 2, [3, 4]]
# Shallow copy
shallow_copy = original_list.copy()
# Modifying the nested list in the shallow copy
shallow_copy[2][0] = 99
print(f"Original list: {original_list}")
print(f"Shallow copy: {shallow_copy}")import copy
# Original dictionary with nested dictionary
original_dict = {'a': 1, 'b': {'c': 2}}
# Shallow copy
shallow_copy = copy.copy(original_dict)
# Modifying the nested dictionary in the shallow copy
shallow_copy['b']['c'] = 99
print(f"Original dict: {original_dict}")
print(f"Shallow copy: {shallow_copy}")Last updated