Dictionary Update in Python
Level 382 keystrokes
This updates a dictionary with another dictionary. The update() method adds new keys and overwrites existing ones.
Python code
# The dictionary to update: a=1, b=21dict1 = {"a": 1, "b": 2}# New values: b also exists in dict1, c does not2dict2 = {"b": 3, "c": 4}# update() changes dict1 in place: b is overwritten (2 → 3) and c is added3dict1.update(dict2)# Prints {'a': 1, 'b': 3, 'c': 4}4print(dict1)Output
{'a': 1, 'b': 3, 'c': 4}Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
"× 8:× 4,× 2(× 2)× 2{× 2}× 2=× 2.× 1