dict.items
Access the key-value pairs of the dictionary.
Python 3.13
dict.items()Return value
A dict_items view of (key, value) pairs that reflects changes to the dictionary.
Examples
Key-value pairs
Python 3.13
a = {'x': 1, 'y': 2}
print(list(a.items()))[('x', 1), ('y', 2)]Looping over pairs
Python 3.13
a = {'x': 1, 'y': 2}
for key, value in a.items():
print(key, value)x 1 y 2
Details
It is most often used in a loop: for key, value in d.items().
