Thanks to visit codestin.com
Credit goes to www.geeksforgeeks.org

Open In App

Convert a List of Tuples into Dictionary - Python

Last Updated : 29 Oct, 2025
Comments
Improve
Suggest changes
14 Likes
Like
Report

Given a list of tuples, the task is to convert it into a dictionary. Each tuple contains a key-value pair, where the first element serves as the key and the second as its corresponding value. For example:

Input: [("a", 1), ("b", 2), ("c", 3)]
Output: {'a': 1, 'b': 2, 'c': 3}

Let's explore different methods to convert a list of tuples into a dictionary.

Using dict()

dict() function converts an iterable of key-value pairs, such as a list of tuples, into a dictionary. It assigns the first element of each tuple as the key and the second as the corresponding value.

Python
a = [("a", 1), ("b", 2), ("c", 3)]
res = dict(a)
print(res)

Output
{'a': 1, 'b': 2, 'c': 3}

Using Dictionary Comprehension

Dictionary comprehension allows creating a dictionary in a single line by iterating over an iterable and specifying key-value pairs. It uses the syntax {key: value for item in iterable} to construct the dictionary efficiently.

Python
a = [("a", 1), ("b", 2), ("c", 3)]  
res = {key: value for key, value in a} 
print(res)

Output
{'a': 1, 'b': 2, 'c': 3}

Using for loop

Using a for loop to create a dictionary involves iterating over an iterable and adding each element as a key-value pair. This can be done by manually assigning values to a dictionary within the loop.

Python
a = [("a", 1), ("b", 2), ("c", 3)]  
res = {}  
for key, value in a:  
    res[key] = value  

print(res)

Output
{'a': 1, 'b': 2, 'c': 3}

Using map() with dict()

map() function applies a given function to each element in an iterable, and when used with dict(), it transforms the result into key-value pairs. This allows for efficient mapping and conversion into a dictionary.

Python
a = [("a", 1), ("b", 2), ("c", 3)]
res = dict(map(lambda x: (x[0], x[1]), a))
print(res)

Output
{'a': 1, 'b': 2, 'c': 3}

Explore