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:
Convert Tuples to Dictionary - Python
Next article icon

Create Dictionary Of Tuples - Python

Last Updated : 12 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The task of creating a dictionary of tuples in Python involves mapping each key to a tuple of values, enabling structured data storage and quick lookups. For example, given a list of names like ["Bobby", "Ojaswi"] and their corresponding favorite foods as tuples [("chapathi", "roti"), ("Paraota", "Idly", "Dosa")], the goal is to generate a dictionary like {'Bobby': ('chapathi', 'roti'), 'Ojaswi': ('Paraota', 'Idly', 'Dosa')}.

Using dictionary literal

This is the most straightforward method to define a dictionary where keys map to tuple values. It is best suited for small, predefined datasets where values do not change frequently. Additionally, Python allows tuples to be used as dictionary keys since they are immutable, making it useful for scenarios where fixed sets of values need mapping.

Python
# tuple of favourite food as key # value is name of student d = {("chapathi", "roti"): 'Bobby',          ("Paraota", "Idly", "Dosa"): 'ojaswi'}  print(d) 

Output
{('chapathi', 'roti'): 'Bobby', ('Paraota', 'Idly', 'Dosa'): 'ojaswi'} 

Table of Content

  • Using dict()
  • Using dictionary comprehension
  • Using default dict

Using dict()

This method allows for dynamic creation of dictionaries from lists, tuples, or other iterables. It is particularly useful when working with structured data from databases, CSV files or APIs, as it provides flexibility in building dictionaries programmatically. This approach is highly efficient when handling large datasets .

Python
d = dict([     ('Bobby', ('chapathi', 'roti')),     ('Ojaswi', ('Paraota', 'Idly', 'Dosa')) ])  print(d) 

Output
{'Bobby': ('chapathi', 'roti'), 'Ojaswi': ('Paraota', 'Idly', 'Dosa')} 

Explanation: dict() constructor converts a list of tuples into a dictionary, where each tuple represents a key-value pair.

Using dictionary comprehension

This approach provides a concise way to construct dictionaries of tuples from existing lists or sequences. It is especially useful when performing data transformations, mapping relationships or filtering elements dynamically. Since dictionary comprehension is optimized in Python, this method ensures better performance over traditional loops while keeping the code clean and readable.

Python
a = ['Bobby', 'Ojaswi']  # name b = [('chapathi', 'roti'), ('Paraota', 'Idly', 'Dosa')]  # food  d = {name: food for name, food in zip(a, b)}  print(d) 

Output
{'Bobby': ('chapathi', 'roti'), 'Ojaswi': ('Paraota', 'Idly', 'Dosa')} 

Explanation: zip(a, b) pairs elements from the two lists a for names and b for food tuples. Dictionary comprehension then constructs a dictionary where names are keys and food tuples are values.

Using default dict

This method is highly useful in scenarios where missing keys should have default tuple values instead of causing a KeyError. It simplifies dictionary handling in cases where data is being incrementally built or updated, such as aggregating user preferences, handling missing data gracefully or setting up default structures for further updates.

Python
from collections import defaultdict  d = defaultdict(tuple) d['Bobby'] = ('chapathi', 'roti') d['Ojaswi'] = ('Paraota', 'Idly', 'Dosa')  print(dict(d)) 

Output
{'Bobby': ('chapathi', 'roti'), 'Ojaswi': ('Paraota', 'Idly', 'Dosa')} 

Explanation: defaultdict(tuple) creates a dictionary with a default tuple value to prevent KeyError for missing keys. Assigning values (d['Bobby'] = ('chapathi', 'roti')) stores names as keys and food tuples as values. dict(d) converts it back to a regular dictionary .


Next Article
Convert Tuples to Dictionary - Python
author
gottumukkalabobby
Improve
Article Tags :
  • Python
  • Python Programs
  • Python dictionary-programs
Practice Tags :
  • python

Similar Reads

  • Convert Dictionary to List of Tuples - Python
    Converting a dictionary into a list of tuples involves transforming each key-value pair into a tuple, where the key is the first element and the corresponding value is the second. For example, given a dictionary d = {'a': 1, 'b': 2, 'c': 3}, the expected output after conversion is [('a', 1), ('b', 2
    3 min read
  • Python | Addition of tuples
    Sometimes, while working with records, we might have a common problem of adding contents of one tuple with the corresponding index of other tuple. This has application in almost all the domains in which we work with tuple records. Let's discuss certain ways in which this task can be performed. Metho
    5 min read
  • Convert Tuples to Dictionary - Python
    The task is to convert a list of tuples into a dictionary where each tuple contains two element . The first element of each tuple becomes the key and the second element becomes the value. If a key appears multiple times its values should be grouped together, typically in a list. For example, given t
    4 min read
  • Python - Concatenate Tuple to Dictionary Key
    Given Tuples, convert them to the dictionary with key being concatenated string. Input : test_list = [(("gfg", "is", "best"), 10), (("gfg", "for", "cs"), 15)] Output : {'gfg is best': 10, 'gfg for cs': 15} Explanation : Tuple strings concatenated as strings. Input : test_list = [(("gfg", "is", "best
    6 min read
  • Python | Add dictionary to tuple
    Sometimes, while working with data, we can have a problem in which we need to append to a tuple a new record which is of form of Python dictionary. This kind of application can come in web development domain in case of composite attributes. Let's discuss certain ways in which this task can be perfor
    4 min read
  • Creating Sets of Tuples in Python
    Tuples are an essential data structure in Python, providing a way to store ordered and immutable sequences of elements. When combined with sets, which are unordered collections of unique elements, you can create powerful and efficient data structures for various applications. In this article, we wil
    3 min read
  • Python | List of tuples to dictionary conversion
    Interconversions are always required while coding in Python, also because of the expansion of Python as a prime language in the field of Data Science. This article discusses yet another problem that converts to dictionary and assigns keys as 1st element of tuple and rest as it's value. Let's discuss
    3 min read
  • Python | Tuple key dictionary conversion
    Interconversions are always required while coding in Python, also because of expansion of Python as a prime language in the field of Data Science. This article discusses yet another problem that converts to dictionary and assigns keys as first pair elements as tuple and rest as it’s value. Let’s dis
    5 min read
  • Convert List of Dictionary to Tuple list Python
    Given a list of dictionaries, write a Python code to convert the list of dictionaries into a list of tuples.Examples: Input: [{'a':[1, 2, 3], 'b':[4, 5, 6]}, {'c':[7, 8, 9], 'd':[10, 11, 12]}] Output: [('b', 4, 5, 6), ('a', 1, 2, 3), ('d', 10, 11, 12), ('c', 7, 8, 9)] Below are various methods to co
    5 min read
  • Python | Dictionary to list of tuple conversion
    Inter conversion between the datatypes is a problem that has many use cases and is usual subproblem in the bigger problem to solve. The conversion of tuple to dictionary has been discussed before. This article discusses a converse case in which one converts the dictionary to list of tuples as the wa
    5 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