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 - In this example, a generator expression is used within the enumerate() function to filter dictionary elements based on a condition. In this case, only cities with a population greater than 3 million are included in the iteration. This showcases how enumerate() can be combined with other Python features to perform more complex operations during iteration.
🌐
Coursera
coursera.org › tutorials › how to enumerate in python: step by step
How to Enumerate in Python: Step by Step | Coursera
February 24, 2023 - 1 2 3 4 programs = ['python','c','react','javascript','bash'] for i, program in enumerate(programs,1): print(i, program) ... Enumerate objects are immutable, which means you cannot change, remove, or add values to them. There are two ways to enumerate a dictionary in Python.
🌐
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' ?

🌐
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).
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.7 documentation
A pair of braces creates an empty dictionary: {}. Placing a comma-separated list of key:value pairs within the braces adds initial key:value pairs to the dictionary; this is also the way dictionaries are written on output.
Find elsewhere
🌐
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.
🌐
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]....
🌐
thwllms
thwllms.com › blog › 2015 › 07 › 12 › enumerate
enumerate() and dict.items() – thwllms
July 12, 2015 - items is similar to enumerate, but for dictionaries. If you were doing this… · >>> my_dict = {0:'a', 1:'b', 2:'c'} >>> for key in my_dict.keys(): ... value = my_dict[key] ... print(key, value) ... 0 a 1 b 2 c · …try this instead: # Python 3 >>> for key, value in my_dict.items(): ...
🌐
Towards Data Science
towardsdatascience.com › home › latest › python enumerate() function, explained
Python enumerate() Function, Explained | Towards Data Science
January 22, 2025 - While key-value pairs in the dictionary are not ordered and not indexed, using enumerate() can be a very useful option for your code. 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.
🌐
W3Schools
w3schools.com › python › python_dictionaries_loop.asp
Python - Loop Dictionaries
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... You can loop through a dictionary by using a for loop.
🌐
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 ...
🌐
Mathspp
mathspp.com › blog › pydonts › enumerate-me
Enumerate me | Pydon't 🐍 | mathspp
April 6, 2021 - the result of enumerate can be ... create a dictionary whose keys are the indices; using enumerate we get a nice idiom to find the indices of an iterable that point to the elements that satisfy a given condition; and · coupling zip, enumerate, and deep unpacking allows you to loop over several iterables elegantly. If you liked this Pydon't be sure to leave a reaction below and share this with your friends and fellow Pythonistas...
🌐
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,
🌐
Quora
quora.com › Can-you-enumerate-a-dictionary-in-Python
Can you enumerate a dictionary in Python? - Quora
Answer (1 of 7): A simple Google search for python enumerate dictionary matched 597,000 pages. Mercifully, Google displays the pages it judges most relevant first in its list, and it tends to be a pretty good judge of relevance. Among the highest ranked of the pages was: Python Enumerate Expl...
🌐
Programiz
programiz.com › python-programming › methods › built-in › enumerate
Python enumerate()
Online Python Online JavaScript ... Online Dart Online R Online Ruby ... The enumerate() function adds a counter to an iterable and returns it as an enumerate object (iterator with index and the value)....
🌐
Built In
builtin.com › software-engineering-perspectives › convert-list-to-dictionary-python
10 Ways to Convert Lists to Dictionaries in Python | Built In
By using collections.ChainMap(), we can convert a list of dictionaries to a single dictionary. “ChainMap: A ChainMap groups multiple dicts or other mappings together to create a single, updateable view,” according to Python’s documentation.
🌐
Onestopdataanalysis
onestopdataanalysis.com › home › enumerate dictionary python
Enumerate Dictionary Python: Everything You need about it
Python Enumerate command was unknown to me for a long time. On this recipe, you will learn how to use it when using a for loop … ... A blog containing scripts and data analysis lessons such as Bioinformatics, Python, GitHub, Docker, Machine Learning, etc.
🌐
Python
docs.python.org › 3 › builtins › functions.html
Built-in Functions — Python 3.14.7 documentation
In an optimized scope (including functions, generators, and coroutines), each call to locals() instead returns a fresh dictionary containing the current bindings of the function’s local variables and any nonlocal cell references.
🌐
freeCodeCamp
freecodecamp.org › news › python-enumerate-python-enum-for-loop-index-example
Python Enumerate – Python Enum For Loop Index Example
September 22, 2021 - Instead of incrementing a count variable ourselves, we can use the enumerate() function with the for loop. Python's built in enumerate() function takes in an iterable and an optional start argument.