Answers for "enumerate dictionary python"

5

python dict enumerate

for i, (k, v) in enumerate(example_dict.items()):
    print(i, k, v)
Posted by: Guest on November-19-2020
0

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
Posted by: Guest on August-22-2020

Python Answers by Framework

Browse Popular Code Answers by Language