Last modified: Nov 19, 2026

Python Enumerate a Dictionary

Dictionaries store data as key-value pairs. Sometimes you need the position of each item too. That is where enumerate helps.

This guide shows you how to enumerate a dictionary in Python. You will see simple examples, common patterns, and useful tips.

What Is enumerate in Python?

enumerate is a built-in Python function. It adds a counter to any iterable. Each loop gives you an index and a value.

Here is the basic syntax.


enumerate(iterable, start=0)

The start argument sets the first index. It defaults to 0. You can change it to 1 or any other number.

If you are new to this tool, the Python Enumerate: Complete Guide covers the basics in more depth.

Why Enumerate a Dictionary?

A dictionary is iterable. But a plain loop gives you only the keys. You often want the index too.

Common use cases include:

Numbering output rows. Tracking loop position. Building ordered reports. Debugging loops.

You can also pair enumerate with other tools. For example, learn how to use the Python zip Function: Combine Iterables to loop over multiple structures at once.

Enumerate Over Dictionary Keys

The simplest way is to loop over the dictionary directly. By default, you get the keys.


scores = {"Alice": 90, "Bob": 85, "Cara": 95}

for index, key in enumerate(scores):
    print(index, key)

0 Alice
1 Bob
2 Cara

This works because a dictionary yields its keys when iterated. The index starts at 0.

You can start at 1 for human-friendly output.


for index, key in enumerate(scores, start=1):
    print(f"{index}. {key}")

1. Alice
2. Bob
3. Cara

Enumerate Over Dictionary Items

Most of the time you want both the key and the value. Use the items method.


scores = {"Alice": 90, "Bob": 85, "Cara": 95}

for index, (key, value) in enumerate(scores.items()):
    print(index, key, value)

0 Alice 90
1 Bob 85
2 Cara 95

Notice the parentheses around key, value. This unpacks each tuple returned by items. It keeps the code clean and readable.

If unpacking feels confusing, check out Python *args and **kwargs Explained for a deeper look at packing and unpacking.

Enumerate Over Dictionary Values

Sometimes you only need the values. Use the values method.


scores = {"Alice": 90, "Bob": 85, "Cara": 95}

for index, value in enumerate(scores.values()):
    print(index, value)

0 90
1 85
2 95

This is useful when you want to number a list of scores or totals.

Convert enumerate Results to a List

You can store the results in a list. This is handy for later processing.


scores = {"Alice": 90, "Bob": 85}

numbered = list(enumerate(scores.items()))
print(numbered)

[(0, ('Alice', 90)), (1, ('Bob', 85))]

Each item is a tuple. The first element is the index. The second element is a key-value tuple.

You can also build a new dictionary from it. This is a common pattern.


scores = {"Alice": 90, "Bob": 85}
indexed = {i: (k, v) for i, (k, v) in enumerate(scores.items())}
print(indexed)

{0: ('Alice', 90), 1: ('Bob', 85)}

Use enumerate with a Lambda

You can pass enumerate objects to functions like map and filter. This makes compact code.


scores = {"Alice": 90, "Bob": 85, "Cara": 95}

# Format each item as "index: key=value"
result = list(map(lambda item: f"{item[0]}: {item[1][0]}={item[1][1]}", enumerate(scores.items())))
print(result)

['0: Alice=90', '1: Bob=85', '2: Cara=95']

This works well for quick transformations. To learn more about these tools, read the Python Lambda vs Function: Key Differences.

Common Mistakes to Avoid

Mistake 1: Forgetting items. Looping over the dictionary gives keys only.


scores = {"Alice": 90}

# Wrong: value is not available
for index, key in enumerate(scores):
    print(index, key)

Mistake 2: Unpacking errors. If you write for index, key, value in enumerate(scores.items()), Python raises a ValueError.

The correct form uses parentheses: for index, (key, value) in ....

Mistake 3: Expecting a sorted result. Dictionaries keep insertion order in Python 3.7+. But they are not sorted by key automatically.

If you need sorted output, sort the items first.


scores = {"Cara": 95, "Alice": 90, "Bob": 85}

for index, (key, value) in enumerate(sorted(scores.items())):
    print(index, key, value)

0 Alice 90
1 Bob 85
2 Cara 95

Performance Notes

enumerate is lazy. It does not create a new list. It yields pairs one at a time. This makes it memory-friendly for large dictionaries.

For very large data, avoid calling list on the result unless you need it. Keep the loop simple and let Python handle the rest.

Practical Example: Numbered Report

Here is a small script that prints a numbered report. It also adds a status label.


scores = {"Alice": 90, "Bob": 85, "Cara": 95}

for index, (name, score) in enumerate(scores.items(), start=1):
    status = "Pass" if score >= 90 else "Review"  # simple check
    print(f"{index}. {name}: {score} ({status})")

1. Alice: 90 (Pass)
2. Bob: 85 (Review)
3. Cara: 95 (Pass)

This pattern is common in reports, logs, and CLI tools. It keeps output readable and easy to scan.

Conclusion

Enumerating a dictionary in Python is simple. Use enumerate with the dictionary, items, or values. Add a start value when you want human-friendly numbering.

Remember the key points. Loop over keys by default. Use items for key-value pairs. Unpack tuples with parentheses. Sort first if order matters.

With these patterns, you can write clean loops that show both position and data. Try them in your next script and see how much clearer your output becomes.