Python dict iteration: Using items to get keys and values

Python dict iteration: Using items to get keys and values

Want to iterate over a Python dict? The “items” method is your friend, returning a (key, value) tuple with each iteration:

d = {'a':10, 'b':20, 'c':30}
for key, value in d.items():
    print(f'{key}: {value}')

Remember: Insertion order determines iteration order.