On top of the already provided answers there is a very nice pattern in Python that allows you to enumerate both keys and values of a dictionary.

The normal case you enumerate the keys of the dictionary:

Use with AIexample_dict = {1:'a', 2:'b', 3:'c', 4:'d'}

for i, k in enumerate(example_dict):
    print(i, k)

Which outputs:

Use with AI0 1
1 2
2 3
3 4

But if you want to enumerate through both keys and values this is the way:

Use with AIfor i, (k, v) in enumerate(example_dict.items()):
    print(i, k, v)

Which outputs:

Use with AI0 1 a
1 2 b
2 3 c
3 4 d
Answer from João Almeida on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › iterate-python-dictionary-using-enumerate-function
Iterate Python Dictionary Using Enumerate() Function - GeeksforGeeks
July 23, 2025 - In this example, the enumerate() function is used with the items() method of the dictionary, which returns key-value pairs. The loop unpacks each pair into variables key and value, while index keeps track of the iteration index.
Discussions

enumerate() for dictionary in Python - Stack Overflow
Keys and values are iterated over ... across Python implementations, and depends on the dictionary’s history of insertions and deletions. If keys, values and items views are iterated over with no intervening modifications to the dictionary, the order of items will directly correspond. That's why you see the indices 0 to 7 in the first column. They are produced by enumerate and are always ... More on stackoverflow.com
🌐 stackoverflow.com
October 9, 2017
python - How to iterate `dict` with `enumerate` and unpack the index, key, and value along with iteration - Stack Overflow
How to iterate a dict with enumerate such that I could unpack the index, key and value at the time of iteration? Something like: for i, (k, v) in enumerate(mydict): # some stuff I want to iter... More on stackoverflow.com
🌐 stackoverflow.com
how to loop through dict with enumerate and unpack the index, key, and value
for i, (k, v) in enumerate(my_result.items()): print(v['charge_usage']) Your value v is just another dictionary. You can do the same things with it that you could do with any dictionary. More on reddit.com
🌐 r/learnpython
8
1
October 13, 2022
Enumerating through a dictionary in Python - Stack Overflow
I am trying to enumerate through a dictionary like this but it does not work. What's the simplest way to iterate through a dictionary in python while enumerating each entry? for i, k, v in enumerate( More on stackoverflow.com
🌐 stackoverflow.com
🌐
Pierian Training
pieriantraining.com › home › enumerating dictionaries in python
Enumerating Dictionaries in Python - Pierian Training
April 28, 2023 - As you can see, enumerating dictionaries using for loops is a simple and effective way to access and manipulate their contents. Python provides several ways to enumerate dictionaries, and one of the most efficient ways is using list comprehension.
🌐
GeeksforGeeks
geeksforgeeks.org › python › enumerate-in-python
Enumerate() in Python - GeeksforGeeks
It returns pairs in the form (index, element). This removes the need to manually maintain a counter variable during iteration. Example: This code shows how enumerate() provides both index and value while iterating over a list.
Published: May 8, 2026
🌐
Python Examples
pythonexamples.org › python-enumerate-a-dictionary
Enumerate a Dictionary
In this example, we will take a dictionary, and enumerate over the key:value pairs of dictionary in a For Loop. fruits = {'apple': 25, 'banana': 14, 'mango':48, 'cherry': 30} for x in enumerate(fruits.items()): print(x) (0, ('apple', 25)) (1, ('banana', 14)) (2, ('mango', 48)) (3, ('cherry', ...
🌐
Towards Data Science
towardsdatascience.com › home › programming › python enumerate() function, explained
Python enumerate() Function, Explained | Towards Data Science
February 20, 2023 - When iterating over key-value pairs ... at each entry in the dictionary: ... my_dict = { 'Apple': 3, 'Banana': 1, 'Orange': 2, 'Pineapple': 5 }for i, (key, value) in enumerate(my_dict.items()): print(i, (key, value)) ... A slightly ...
🌐
Coursera
coursera.org › tutorials › how to enumerate in python: step by step
How to Enumerate in Python: Step by Step | Coursera
February 24, 2023 - Try using enumerate to add a counter to the keys of this dictionary: ... 1 pokemon = {'Pikachu': 'Electric', 'Bulbasaur': 'Grass/Poison', 'Squirtle':'Water', 'Charmander':'Fire'} ... The code works in the same way as the previous examples with ...
Find elsewhere
🌐
EyeHunts
tutorial.eyehunts.com › home › python enumerate dictionary | example code
Python enumerate dictionary | Example code
April 5, 2023 - example_dict = {1: 'a', 2: 'b', 3: 'c', 4: 'd'} for i, (k, v) in enumerate(example_dict.items()): print(i, k, v) ... Do comment if you have any doubts or suggestions on this Python enumerate topic.
🌐
Simplilearn
simplilearn.com › home › resources › software development › an introduction to enumerate in python with syntax and examples
An Introduction to Enumerate in Python with Syntax and Examples
August 24, 2025 - Enumerate is a built-in function in the python library. This tutorial will help you to learn all about enumerate in python with syntax and examples. Start now!
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
CodeRivers
coderivers.org › blog › python-enumerate-dictionary
Python Enumerate with Dictionaries: A Comprehensive Guide - CodeRivers
February 22, 2026 - Its basic syntax is enumerate(sequence, start=0). The sequence is the iterable object you want to loop over, and start is an optional argument that specifies the starting index (default is 0). Dictionaries are Python's built-in associative data type. They are defined using curly braces {} and ...
🌐
CodeRivers
coderivers.org › blog › python-dictionary-enumerate
Python Dictionary Enumerate: A Comprehensive Guide - CodeRivers
February 22, 2026 - In Python, the `enumerate` function is a powerful tool that simplifies working with iterable objects, such as lists, tuples, and even dictionaries. When dealing with dictionaries, `enumerate` can be used in some creative ways to access both the keys and values along with an index.
🌐
freeCodeCamp
freecodecamp.org › news › what-is-enumerate-in-python
What is enumerate() in Python? Enumeration Example
December 22, 2022 - First, let's look at enumerate(iterable, start=0). ... an iterable, such as a list, tuple, string, dictionary or any object which has the __next__ and __iter__ methods defined (which means it supports iteration).
🌐
Medium
medium.com › @kerinmulianto › exploring-pythons-enumerate-a-beginner-s-guide-62f1c9265e45
Exploring Python’s enumerate: A Beginner’s Guide | by Kerinmulianto | Medium
November 24, 2024 - This guide introduces Python’s enumerate function, which simplifies tracking indices while iterating through lists, tuples, and strings. It provides examples for using enumerate with lists, dictionaries, and strings, showing how it makes code cleaner and more efficient compared to manually ...
🌐
Python Guides
pythonguides.com › enumerate-in-python
What Does enumerate() Do in Python? (With Examples)
1 month ago - for i, letter in enumerate("Ohio"): print(i, letter, end=" ") print() capitals = {"TX": "Austin", "CA": "Sacramento"} for i, (state, city) in enumerate(capitals.items(), start=1): print(i, state, city) with open("orders.txt", "w") as f: ...
🌐
Reddit
reddit.com › r/learnpython › how to loop through dict with enumerate and unpack the index, key, and value
r/learnpython on Reddit: how to loop through dict with enumerate and unpack the index, key, and value
October 13, 2022 -

an example of the dict

{10: {'total_power_usage': 152.1, 'total_pris': 336.62499999999994, 'huse_usage': 74.45588194444376, 'hus_pris': 195.42238509638779, 'charge_usage': 77.64411805555619, 'charge_price_full': 141.1951349036122, 'charge_price': 63.55101684805601}}

now i can do :

for i, (k, v) in enumerate(my_result.items()):
    print("index: {}, key: {}, value: {}".format(i, k, v))

and that prints each line in the dict just fine. But how do i access each named element in the dict? if i need the value from 'total_pris' or 'charge_usage' ?

🌐
Python Central
pythoncentral.io › how-to-use-the-enumerate-function
How to Use the Enumerate() Function | Python Central
November 1, 2023 - It's interesting to note that you ... the more Pythonic approach to achieving this task. The items() method returns a collection of key-value pairs you can iterate. Let's see how you can apply the items() method: In this example, we directly iterate over the dictionary sample_dict. The code prints both the key and the value for each item in the dictionary. Using enumerate() is not necessary ...
🌐
Medium
medium.com › @codingcampus › enumerate-function-in-python-1385a927b179
Enumerate() Function in Python. In programming, we often have to deal… | by CodingCampus | Medium
November 23, 2023 - for index, fruit in enumerate(fruit_pair.items(), start=1):print (index, fruit)[/python] ... Indexing a dictionary with the enumerate function and the items method. The items() function is important for this step; otherwise, our code will print only the key of the dictionary and the index of that key. For example: