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
🌐
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: ... Finally, ...
Discussions

python - Enumerate Dictionary Iterating Key and Value - Stack Overflow
I have a dictionary called regionspointcount that holds region names (str) as the keys and a count of a type of feature within that region (int) as the values e.g. {'Highland':21}. I am wanting to 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
What is the fastest way to iterate over a dictionary?
try again but this time do "for key, vals in dictName.items()" first and "for vals in dictName.values():" second see if your times still hold More on reddit.com
🌐 r/learnpython
17
99
January 4, 2023
🌐
Real Python
realpython.com › iterate-through-dictionary-python
How to Iterate Through a Dictionary in Python – Real Python
September 9, 2025 - By understanding these techniques, ... You can directly iterate over the keys of a Python dictionary using a for loop and access values with dict_object[key]....
🌐
Coursera
coursera.org › tutorials › how to enumerate in python: step by step
How to Enumerate in Python: Step by Step | Coursera
February 24, 2023 - The .items() method returns a list of key-value pairs from the dictionary, which can then be passed to enumerate().
🌐
GeeksforGeeks
geeksforgeeks.org › python › iterate-python-dictionary-using-enumerate-function
Iterate Python Dictionary Using Enumerate() Function - GeeksforGeeks
July 23, 2025 - Index: 0, Key: a, Value: 1 Index: 1, Key: b, Value: 2 Index: 2, Key: c, Value: 3 Index: 3, Key: d, Value: 4 · In this example, the enumerate() function accepts an additional argument, start, which determines the starting value of the index. By setting start=1, we begin indexing from 1 instead of the default 0. This is particularly useful when presenting results to users or when indexing starts at 1 in a specific context. ... # Sample dictionary grades = {'Alice': 90, 'Bob': 85, 'Charlie': 92, 'David': 78} # Iterating with a custom start index for position, (student, score) in enumerate(grades.items(), start=1): print(f"Position: {position}, Student: {student}, Score: {score}")
Find elsewhere
🌐
Python Examples
pythonexamples.org › python-enumerate-a-dictionary
Enumerate a Dictionary
In this example, we will take a ... (3, ('cherry', 30)) In this tutorial of Python Examples, we learned how to enumerate a dictionary using enumerate() builtin function....
🌐
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 consist of key-value pairs...
🌐
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.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Iterate Over Dictionary Keys, Values, and Items in Python | note.nkmk.me
April 24, 2025 - In Python, you can iterate over a dictionary (dict) using the keys(), values(), or items() methods in a for loop. You can also convert the keys, values, or items of a dictionary into a list using the list() function.
🌐
EyeHunts
tutorial.eyehunts.com › home › python enumerate dictionary | example code
Python enumerate dictionary | Example code
April 5, 2023 - You will get keys in this method. example_dict = {1: 'a', 2: 'b', 3: 'c', 4: 'd'} for i, k in enumerate(example_dict): print(i, k) ... 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.
🌐
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' ?

🌐
W3Schools
w3schools.com › python › python_dictionaries_loop.asp
Python - Loop Dictionaries
When looping through a dictionary, the return value are the keys of the dictionary, but there are methods to return the values as well.
🌐
Towards Data Science
towardsdatascience.com › home › programming › python enumerate() function, explained
Python enumerate() Function, Explained | Towards Data Science
February 20, 2023 - The main difference in the output is that when iterating over a dictionary, you have the option of iterating over dictionary keys, dictionary values, or dictionary key-value pairs. ... my_dict = { 'Apple': 3, 'Banana': 1, 'Orange': 2, 'Pineapple': 5 }for i, key in enumerate(my_dict.keys()): print(i, key)
🌐
Python-Fiddle
python-fiddle.com › tutorials › enumerate
Python enumerate function
# Define a dictionary fruit_colors = {"apple": "red", "banana": "yellow", "cherry": "red"} # Use enumerate to iterate over dictionary keys with an index for index, key in enumerate(fruit_colors.keys()): print(f"Index: {index}, Key: {key}")
🌐
Jmcgowan
wordpress.jmcgowan.com › wp › the-python-enumerate-function-and-dictionaries
The Python enumerate() Function and Dictionaries – Mathematical Software
June 18, 2019 - pets_dict.items() returns a dict_items container with the list of (key, value) tuples in the dictionary. By default, Python enumerate() is applied to the keys in the dictionary. Remember the for loop in Python defaults to looping over the keys ...
🌐
Sentry
sentry.io › sentry answers › python › iterate over a dictionary in python
Iterate Over a Dictionary in Python with For Loops | Sentry
September 10, 2026 - Loop through Python dictionary keys directly, use items() to access key-value pairs together, or add enumerate() for positional indexing during iteration
🌐
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