Skip to content
  • (+91) 9409548155
  • support@appdividend.com
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Menu
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
  • Home
  • Pricing
  • Instructor
  • Tutorials
    • Laravel
    • Python
    • React
    • Javascript
    • Angular
  • Become A Tutor
  • About Us
  • Contact Us
Python

How to Convert List to Dictionary in Python

  • 12 Nov, 2025
  • Com 0
How to convert a list to dictionary in Python

Converting a list to a dictionary in Python demands the type of input data you have and what your dictionary looks like.

For example, if you have two lists as input, you can create a dictionary from them, where the first list serves as the keys and the second list serves as the values. That way, it would become a meaningful dictionary.

It is also possible that you have a list or tuple of tuples and you want to convert it to a meaningful dictionary. In that case, the approach will be different.

Another case is that you have only one list and use the list indices as keys, with the list values serving as the dictionary values.

So, you have multiple approaches, each tailored for separate use cases.

Method 1: Using dict() and zip() methods

Imagine that you have two parallel lists, one for dict keys and another for dict values. The fastest way to convert them into a dictionary is to use the zip() method in combination with the dict() method.

I highly recommend this approach if you are working with two lists.

The zip() method combines both lists to create an iterator and then converts that iterator to a dictionary using the dict() method.

Using dict() and zip() methods to convert a list to a dictionary in Python

ott_keys = ['Disney', 'Netflix', 'Hulu']
print(type(ott_keys))
# Output: <class 'list'>

ott_values = [10, 20, 30]
print(type(ott_keys))
# Output: <class 'list'>

ott_dict = dict(zip(ott_keys, ott_values))

print(ott_dict)
# Output: {'Disney': 10, 'Netflix': 20, 'Hulu': 30}

print(type(ott_dict))
# Output: <class 'dict'>

In this code, the zip() function pairs elements (like (‘Disney’, 10)). The dict() method then converts pairs into a dictionary. It is a clean and Pythonic approach.

Method 2: Using Dictionary Comprehension

Another easy way is dictionary comprehension for two separate input lists. It iterates over the indices of the keys list.

For each iteration, it takes an element from the keys list as the key and the corresponding element from the values list as the value.

The main advantage of dictionary comprehension is that it helps us in custom conversion logic.

Using Dictionary Comprehension to convert two lists to a dictionary in Python

 

ott_keys = ['Disney', 'Netflix', 'Hulu']
print(type(ott_keys))
# Output: <class 'list'>

ott_values = [10, 20, 30]
print(type(ott_keys))
# Output: <class 'list'>

ott_dict = {ott_keys[i]: ott_values[i]*4 for i in range(len(ott_keys))}

print(ott_dict)
# Output: {'Disney': 40, 'Netflix': 80, 'Hulu': 120}
print(type(ott_dict))
# Output: <class 'dict'>

In this code, while transforming to a dictionary, we multiplied the value by 4 for each key in the output dictionary.

Method 3: Using dict() with list of tuples or lists

If you have a list of tuples, where each tuple contains two elements (key, value), you can directly convert it into a dictionary using dict().

Similarly, if you have a list of lists, where each inner list contains two elements (key, value), you can use this method.

Using dict() with list of tuples or lists

 

list_of_tuples = [('Disney', 10), ('Netflix', 20), ('Hulu', 30)]

print(list_of_tuples)
# Output: [('Disney', 10), ('Netflix', 20), ('Hulu', 30)]

print(type(list_of_tuples))
# Output: <class 'list'>

ott_dict = dict(list_of_tuples)

print(ott_dict)
# Output: {'Disney': 10, 'Netflix': 20, 'Hulu': 30}

print(type(ott_dict))
# Output: <class 'dict'>

This approach is best when each element already has a key-value structure, and it is speedy.

Method 4: Using enumerate() — List Index as Key

What if you have only a single list and need to convert it to a dictionary? Since a list only has values for the dictionary, how will we create keys for the dict? That’s when you need to map list indices to values.

Using enumerate() — List Index as Key

ott_list = ["Disney", "Netflix", "Hulu"]

print(ott_list)
# Output: ['Disney', 'Netflix', 'Hulu']

print(type(ott_list))
# Output: <class 'list'>

ott_dict = dict(enumerate(ott_list))

print(ott_dict)
# Output: {0: 'Disney', 1: 'Netflix', 2: 'Hulu'}

print(type(ott_dict))
# Output: <class 'dict'>

In the above output, you can see that it automatically generates index-based keys, and values are list elements.

Method 5: Using dict.fromKeys()

If you have a list of keys and want to assign the same value to each key, you can use the dict.fromkeys() method. This approach is helpful when you want the same default value for all keys.

Using dict.fromKeys() to convert a list to dict in Python

 

ott_keys = ["Disney", "Netflix", "Hulu"]

print(ott_keys)
# Output: ['Disney', 'Netflix', 'Hulu']

print(type(ott_keys))
# Output: <class 'list'>

ott_values = 10

ott_dict = dict.fromkeys(ott_keys, ott_values)

print(ott_dict)
# Output: {'Disney': 10, 'Netflix': 10, 'Hulu': 10}

print(type(ott_dict))
# Output: <class 'dict'>

 That’s all!

Post Views: 6
Share on:
Krunal Lathiya

With a career spanning over eight years in the field of Computer Science, Krunal’s expertise is rooted in a solid foundation of hands-on experience, complemented by a continuous pursuit of knowledge.

How to Split String (Tokens) on Multiple Delimiters in Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Address: TwinStar, South Block – 1202, 150 Ft Ring Road, Nr. Nana Mauva Circle, Rajkot(360005), Gujarat, India

Call: (+91) 9409548155

Email: support@appdividend.com

Online Platform

  • Pricing
  • Instructors
  • FAQ
  • Refund Policy
  • Support

Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms of services

Tutorials

  • Angular
  • React
  • Python
  • Laravel
  • Javascript
Copyright @2024 AppDividend. All Rights Reserved
Appdividend