iter over dictionary python code example

Example 1: python loop through dictionary

dictionary = {52:"E",126:"A",134:"B",188:"C",189:"D"}
for key, value in dictionary.items():
	print(key)
	print(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