for loop that runs ech key and value python code example

Example 1: python iterate dictionary key value

a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
for key, value in a_dict.items():
  print(key, '->', value)

Example 2: enumerate dictionary python

# Iterate over dictionary using enumerate()

mydict = {
	"one": 1,
  	"two": 2,
  	"three": 3
}

# You can replace `index` with an underscore to ignore the index 
# value if you don't plan to use it.
for index, item in enumerate(mydict):
	print(f"{item}: {mydict.get(item)}")

# OUTPUT:
# one: 1
# two: 2
# three: 3