ChainMap in Python
Level 4258 keystrokes
This uses ChainMap to combine multiple dictionaries into a single view, with earlier dicts taking priority.
Python code
# Import ChainMap from collections1from collections import ChainMap2 # Default values3defaults = {"color": "red", "size": "medium"}# User preferences that override only color4user_prefs = {"color": "blue"}5 # Earlier dicts take priority: user_prefs is searched first6config = ChainMap(user_prefs, defaults)7 # Found in user_prefs: blue8print(f"color: {config['color']}")# Not in user_prefs, so it comes from defaults: medium9print(f"size: {config['size']}")# keys() merges the keys of all dicts without duplicates10print(f"keys: {list(config.keys())}")Output
color: blue size: medium keys: ['color', 'size']
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.
"× 18:× 6(× 6)× 6{× 5}× 5'× 4=× 3_× 2,× 2