Sobes.tech
Junior

How to iterate over a dictionary by key-value pairs?

sobes.tech AI

Answer from AI

Use the .items() method.

# Example: iterating over a dictionary
my_dict = {'a': 1, 'b': 2, 'c': 3}

for key, value in my_dict.items():
    # Processing key and value
    print(f"Key: {key}, Value: {value}")