Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python - Convert list of dictionaries to JSON
Next article icon

Convert a list of Tuples into Dictionary – Python

Last Updated : 07 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Converting a list of tuples into a dictionary involves transforming each tuple, where the first element serves as the key and the second as the corresponding value. For example, given a list of tuples a = [(“a”, 1), (“b”, 2), (“c”, 3)], we need to convert it into a dictionary. Since each key-value pair from the tuples matches a valid dictionary structure, the expected output is {‘a’: 1, ‘b’: 2, ‘c’: 3}. Let’s explore different methods to achieve this.

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} 

Explanation: dict(a) constructor iterates through the list of tuples a , extracting the first element of each tuple as a key and the second as its corresponding value, forming a dictionary.

Table of Content

  • Using dictionary comprehension
  • Using for loop
  • Using map() with dict()

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} 

Explanation: {key: value for key, value in a} iterates through each tuple, assigning the first element as the key and the second as the value, efficiently constructing a dictionary.

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 = {}    # Populate the dictionary  for key, value in a:       res[key] = value    print(res) 

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

Explanation: for loop iterates through each tuple, assigning the first element as the key and the second as the value. Each key-value pair is added to res, constructing the dictionary.

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} 

Explanation: map() function applies a lambda function to each tuple, extracting the first element as the key and the second as the value. The dict() constructor then converts the mapped key-value pairs into a dictionary.



Next Article
Python - Convert list of dictionaries to JSON
author
chinmoy lenka
Improve
Article Tags :
  • Python
  • Python dictionary-programs
  • python-dict
  • python-tuple
Practice Tags :
  • python
  • python-dict

Similar Reads

  • Python | Convert list of tuple into dictionary
    Given a list containing all the element and second list of tuple depicting the relation between indices, the task is to output a dictionary showing the relation of every element from the first list to every other element in the list. These type of problems are often encountered in Coding competition
    8 min read
  • Convert Two Lists into a Dictionary - Python
    We are given two lists, we need to convert both of the list into dictionary. For example we are given two lists a = ["name", "age", "city"], b = ["Geeks", 30,"Delhi"], we need to convert these two list into a form of dictionary so that the output should be like {'name': 'Geeks', 'age': 30, 'city': '
    3 min read
  • Python - Convert list of dictionaries to JSON
    In this article, we will discuss how to convert a list of dictionaries to JSON in Python. Python Convert List of Dictionaries to JsonBelow are the ways by which we can convert a list of dictionaries to JSON in Python: Using json.dumps()Using json.dump()Using json.JSONEncoderUsing default ParameterDi
    5 min read
  • Filter Dictionary of Tuples by Condition - Python
    This task involves filtering the items of a dictionary based on a specific condition applied to the values, which are tuples in this case. We will check certain conditions for each tuple in the dictionary and select the key-value pairs that satisfy the condition. Given the dictionary a = {'a': (6, 3
    3 min read
  • Convert List Of Tuples To Json Python
    Working with data often involves converting between different formats, and JSON is a popular choice for data interchange due to its simplicity and readability. In Python, converting a list of tuples to JSON can be achieved through various approaches. In this article, we'll explore four different met
    3 min read
  • Ways to create a dictionary of Lists - Python
    A dictionary of lists is a type of dictionary where each value is a list. These dictionaries are commonly used when we need to associate multiple values with a single key. Initialize a Dictionary of ListsThis method involves manually defining a dictionary where each key is explicitly assigned a list
    3 min read
  • Create a List of Tuples in Python
    The task of creating a list of tuples in Python involves combining or transforming multiple data elements into a sequence of tuples within a list. Tuples are immutable, making them useful when storing fixed pairs or groups of values, while lists offer flexibility for dynamic collections. For example
    3 min read
  • Convert Lists to Nested Dictionary - Python
    The task of converting lists to a nested dictionary in Python involves mapping elements from multiple lists into key-value pairs, where each key is associated with a nested dictionary. For example, given the lists a = ["gfg", "is", "best"], b = ["ratings", "price", "score"], and c = [5, 6, 7], the g
    3 min read
  • Convert Tuple to List in Python
    In Python, tuples and lists are commonly used data structures, but they have different properties: Tuples are immutable: their elements cannot be changed after creation.Lists are mutable: they support adding, removing, or changing elements.Sometimes, you may need to convert a tuple to a list for fur
    2 min read
  • Python - Converting list string to dictionary
    Converting a list string to a dictionary in Python involves mapping elements from the list to key-value pairs. A common approach is pairing consecutive elements, where one element becomes the key and the next becomes the value. This results in a dictionary where each pair is represented as a key-val
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences