Converting a list into a dictionary where each item’s index becomes the key can be used when you want quick access to elements by their position.
In this article, you’ll learn multiple ways to convert a list to a dictionary with the index as the key with multiple examples.
fruits = ['apple', 'banana', 'cherry']
output = {0: 'apple', 1: 'banana', 2: 'cherry'}
Method 1: Using Dictionary Comprehension (Best & Pythonic Way)
fruits = ['apple', 'banana', 'cherry']
# Convert list to dict using comprehension
fruit_dict = {index: value for index, value in enumerate(fruits)}
print(fruit_dict)
Output:
{0: 'apple', 1: 'banana', 2: 'cherry'}
Why use this?
> Works for any iterable
> Allows additional conditions (like filtering)
Method 2: Using dict() with enumerate()
The enumerate() function adds an index to each item, and you can directly pass it to dict().
fruits = ['apple', 'banana', 'cherry']
fruit_dict = dict(enumerate(fruits))
print(fruit_dict)
Output:
{0: 'apple', 1: 'banana', 2: 'cherry'}
This method is Very efficient for direct index mapping.
Method 3: Using a Simple Loop
If you prefer an explicit loop:
fruits = ['apple', 'banana', 'cherry']
fruit_dict = {}
for index in range(len(fruits)):
fruit_dict[index] = fruits[index]
print(fruit_dict)
Output:
{0: 'apple', 1: 'banana', 2: 'cherry'}
Method 4: Using zip() with range()
You can also pair range() (for indices) and your list (for values):
fruits = ['apple', 'banana', 'cherry']
fruit_dict = dict(zip(range(len(fruits)), fruits))
print(fruit_dict)
Output:
{0: 'apple', 1: 'banana', 2: 'cherry'}
This method works when you need more control over index generation (like starting from 1).
You can easily shift the index using start in enumerate():
fruit_dict = {index: value for index, value in enumerate(fruits, start=1)}
FAQs — Convert Python List to Dictionary with Index as Key
How do I convert a list to a dictionary with index as the key in Python?
The simplest and most Pythonic way is to use dict(enumerate(list_name)). It automatically uses the list’s index positions as dictionary keys.
my_list = ['apple', 'banana', 'cherry']
my_dict = dict(enumerate(my_list))
print(my_dict)
# Output: {0: 'apple', 1: 'banana', 2: 'cherry'}
How can I make the index start from 1 instead of 0?
Use the start parameter in enumerate() to customize the starting index.
my_dict = dict(enumerate(my_list, start=1))
# Output: {1: 'apple', 2: 'banana', 3: 'cherry'}
Can I use dictionary comprehension instead of dict(enumerate())?
Yes — dictionary comprehension gives more flexibility and readability when you want to modify elements while converting.
my_dict = {i: item.upper() for i, item in enumerate(my_list)}
# Output: {0: 'APPLE', 1: 'BANANA', 2: 'CHERRY'}
How can I convert only a portion of a list into a dictionary?
Slice the list before converting to dictionary:
dict(enumerate(my_list[:2]))
# Output: {0: 'apple', 1: 'banana'}
What happens if the list is empty?
If your list is empty, dict(enumerate([])) will return an empty dictionary {} without errors.
Can I convert a nested list into a dictionary with indices?
Yes. Each nested list or tuple will simply become a value in the dictionary:
nested = [[1,2], [3,4], [5,6]]
dict(enumerate(nested))
# Output: {0: [1, 2], 1: [3, 4], 2: [5, 6]}
What’s the difference between enumerate() and range(len()) in this case?
Both can be used, but enumerate() is cleaner and faster since it yields both index and value automatically. The range(len(list)) approach requires manual indexing:
{i: my_list[i] for i in range(len(my_list))}
Is converting a list to a dictionary efficient for large lists?
Yes. Both enumerate() and dict() are implemented in C, making them very fast even for large lists with millions of elements.