Merging and Updating Dictionaries With Operators
Merging and Updating Dictionaries With Operators. Python 3.9 added two new operators in the dictionary space. Now you have merge (
|) and update (
|=) dictionary operators.
These operators also work with
00:42 As the name suggests, the merge operator merges the two dictionaries into a new one that contains the items of both initial dictionaries. If the dictionaries in the expression have common keys, then the rightmost dictionary’s value will prevail.
The update operator is handy when you have a dictionary and want to update some of its values without calling
01:21 Here, you use the dictionary update operator to update Newton’s lifetime information. The operator updates the dictionary in place. If the dictionary with the updated data has new keys, then those keys are added to the end of the original dictionary.
01:40 In the next section of the course, you’ll take a look at performance.
Become a Member to join the conversation.