Source Code:
(back to article)
import copy original_dict = {'key1': [1, 2, 3], 'key2': 'value2'} new_dict = copy.deepcopy(original_dict) # Update the value of the mutable object in the new dictionary new_dict['key1'][0] = 4 print(original_dict) # {'key1': [1, 2, 3], 'key2': 'value2'} print(new_dict) # {'key1': [4, 2, 3], 'key2': 'value2'}
Result:
Report an issue