Dictionary Items in Python
Level 255 keystrokes
This iterates over key-value pairs using the items() method of a dictionary.
Python code
# Create a dictionary with two key-value pairs1d = {"a": 1, "b": 2}# items() returns key-value pairs as tuples# k gets the key, v gets the value in each iteration2for k, v in d.items(): # Print each key and its corresponding value3 print(k, v)Output
a 1 b 2
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.
"× 4,× 3:× 3(× 2)× 2.× 1{× 1}× 1=× 1