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:

example_dict = {1:'a', 2:'b', 3:'c', 4:'d'}

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

Which outputs:

0 1
1 2
2 3
3 4

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

for i, (k, v) in enumerate(example_dict.items()):
    print(i, k, v)

Which outputs:

0 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 - Python dictionaries are versatile data structures used to store key-value pairs. When it comes to iterating through the elements of a dictionary, developers often turn to the enumerate() function for its simplicity and efficiency.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › iterate python dictionary using enumerate() function
Iterate Python Dictionary using enumerate() Function - Spark By {Examples}
May 31, 2024 - You can iterate a Python dictionary using the enumerate() function. which is used to iterate over an iterable object or sequence such as a list,
Discussions

enumerate() for dictionary in Python - Stack Overflow
Python does not guarantee key order when using enumerate; it is potentially possible for keys to be emitted in a different order on subsequent runs. @roadrunner66's answer is the most correct solution. 2021-08-23T20:13:05.66Z+00:00 ... Save this answer. ... Show activity on this post. The first column of output is the index of each item in enumm and the second one is its keys. If you want to iterate your dictionary ... More on stackoverflow.com
🌐 stackoverflow.com
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? ... I want to iterate through the keys and values in a dictionary called mydict and count them, so I know when I'm on the last pair. 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
python - How to iterate over dictionary using 'enumerate' without assigning loop count to 'key'? - Stack Overflow
I have csv file with three headers( A, B and C) , I read this file as dictionary . Where the headers are Keys in the dictionary , and rows are the keys values. I need to iterate over the dictionary More on stackoverflow.com
🌐 stackoverflow.com
October 18, 2020
🌐
Real Python
realpython.com › iterate-through-dictionary-python
How to Iterate Through a Dictionary in Python – Real Python
September 9, 2025 - In this tutorial, you'll take a deep dive into how to iterate through a dictionary in Python. Dictionaries are a fundamental data type in Python, and you can solve various programming problems by iterating through them.
🌐
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', 30)) In this tutorial of Python Examples, we learned how to enumerate a dictionary using enumerate() builtin function.
🌐
Sentry
sentry.io › sentry answers › python › iterate over a dictionary in python
Iterate over a dictionary in Python | Sentry
January 30, 2023 - Below, we’ve rewritten our code ... word_counts.items(): print(f"{key}: {value}") You can also use the enumerate() function to get the index and key-value in the iteration....
Find elsewhere
🌐
Pierian Training
pieriantraining.com › home › enumerating dictionaries in python
Enumerating Dictionaries in Python - Pierian Training
April 28, 2023 - To enumerate a dictionary in Python, you can use a for loop. Let’s say we have a dictionary of students and their ages: ... Similarly, if we want to iterate over the values in the dictionary, we can use the `values()` method:
🌐
Delft Stack
delftstack.com › home › howto › python › enumerate dictionary python
How to Enumerate Dictionary in Python | Delft Stack
February 2, 2024 - Explanation: Here, the values() method returns an iterable containing the dictionary values. The loop then iterates through these values, providing a concise way to focus solely on the data.
🌐
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' ?

🌐
TheLinuxCode
thelinuxcode.com › home › iterate a python dictionary using enumerate(): practical patterns, edge cases, and real-world recipes
Iterate a Python Dictionary Using enumerate(): Practical Patterns, Edge Cases, and Real-World Recipes – TheLinuxCode
February 8, 2026 - If you remember one mental model, use this: a dict is like a labeled filing cabinet; enumerate() is the sticky note counter you put on each file as you pull it out. It tells you “this is the 7th file I pulled,” not “this file’s label is 7.” · Most loops over dictionaries should be explicit about what you’re iterating. Python gives you three main “views”:
🌐
GeeksforGeeks
geeksforgeeks.org › python › iterate-over-a-dictionary-in-python
Iterate Over a Dictionary in Python - GeeksforGeeks
July 16, 2026 - Given a dictionary, the task is to iterate through its elements. Depending on the requirement, we can iterate over the keys, values, or both key-value pairs. For Example: Input: d = {"name": "Kate", "age": 25} Output: name Kate age 25 · Now, let's explore different methods to iterate over a dictionary in Python.
🌐
Python Guides
pythonguides.com › iterate-through-dictionary-python
Iterate Through a Python Dictionary with Multiple Values
September 23, 2025 - This code creates a new dictionary that stores the number of cities each customer has. It’s concise and Pythonic, making it a great option when you need quick transformations. There are times when I want to access values by their index while iterating. In that case, I use the enumerate() function in Python.
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › python-enumerate
Python Enumerate(): Everything You Should Know
August 7, 2024 - Looking to kickstart your coding journey? Register now for our Programming Courses. Python Enumerate is used when you need the index of an element in a loop along with the element inside it.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Iterate Over Dictionary Keys, Values, and Items in Python | note.nkmk.me
April 24, 2025 - The values() method returns dict_values, which can be converted to a list using list(). print(d.values()) # dict_values([1, 2, 3]) print(type(d.values())) # <class 'dict_values'> ... To iterate over dictionary key-value pairs, use the items() method.
🌐
W3Schools
w3schools.com › python › gloss_python_loop_dictionary_items.asp
Python Loop Through a Dictionary
When looping through a dictionary, the return value are the keys of the dictionary, but there are methods to return the values as well. Print all key names in the dictionary, one by one: ... Python Dictionaries Tutorial Dictionary Access Dictionary Items Change Dictionary Item Check if Dictionary Item Exists Dictionary Length Add Dictionary Item Remove Dictionary Items Copy Dictionary Nested Dictionaries
🌐
StrataScratch
stratascratch.com › blog › how-to-iterate-over-a-dictionary-in-python
How to Iterate Over a Dictionary in Python? - StrataScratch
December 11, 2025 - As we start to look into more advanced ... quickly summarize the value of these two approaches: Use enumerate to call the index of a dictionary along with key-value pairs....
🌐
Reddit
reddit.com › r/learnpython › more pythonic way of iterating through a dictionary?
More pythonic way of iterating through a dictionary? : r/learnpython
February 21, 2023 - enumerate is a built-in that gives you an index for an iterator ... It looks like you're mutating a dictionary to update it each folder, in that it retains values. What you're doing is a using predefined indices to label lines.