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 Lists to Tuple of Tuples
Next article icon

Convert Tuple Value List to List of Tuples – Python

Last Updated : 21 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

We are given a dictionary with values as a list of tuples and our task is to convert it into a list of tuples where each tuple consists of a key and its corresponding value. Note: Each key will appear with each value from the list of tuples. For example: We have a dictionary dict = {‘Gfg’ : [(5, ), (6, )], ‘is’ : [(5, )], ‘best’ :[(7, )]} then output will be [(‘Gfg’, 5), (‘Gfg’, 6), (‘is’, 5), (‘best’, 7)] 

Using * Operator ( unpacking operator)

In this method we iterate through the dictionary and use the unpacking * operator to extract values from the tuples and map them to their respective keys.

Python
d = {'Gfg' : [(5, ), (6, )], 'is' : [(5, )], 'best' :[(7, )]}  # using items() to extract all items and pair key with tuple values res = [] for k, v in d.items():     for ele in v:         res.append((k, *ele))  print("Converted tuple list: " + str(res)) 

Output
Converted tuple list: [('Gfg', 5), ('Gfg', 6), ('is', 5), ('best', 7)] 

Let’s explore other methods to achieve the same:

Table of Content

  • Using List Comprehension + * Operator
  • Using map() and lambda Function
  • Using a dictionary comprehension

Using List Comprehension + * Operator

This method is quite similar to using * Operator ( unpacking operator) method but the only difference is that we get a one-liner solution using list comprehension.

Python
d = {'Gfg' : [(5, ), (6, )], 'is' : [(5, )], 'best' :[(7, )]}  # list comprehension to pair key with tuple values res = [(k, *ele) for k, v in d.items() for ele in v]  print("Converted tuple list: " + str(res)) 

Output
Converted tuple list: [('Gfg', 5), ('Gfg', 6), ('is', 5), ('best', 7)] 

Using map() and lambda Function

map() function with a lambda is used to transform each key-value pair from the dictionary. For each key-value pair, it creates a list of tuples where the key is prepended to the unpacked tuple values and at last the nested list is flattened using list comprehension.

Python
d = {'Gfg': [(5, ), (6, )], 'is': [(5, )], 'best':[(7, )]}  # map and lambda to pair key with tuple values res = list(map(lambda x: [(x[0], *y) for y in x[1]], d.items()))  res = [item for sublist in res for item in sublist]  print("Converted tuple list: " + str(res)) 

Output
Converted tuple list: [('Gfg', 5), ('Gfg', 6), ('is', 5), ('best', 7)] 

Explanation: lambda x: [(x[0], *y) for y in x[1]] takes the key (x[0]) and prepends it to each tuple in the value list (x[1]) and the * operator unpacks the tuple into separate elements.

Using a dictionary comprehension

This method uses dictionary comprehension to first create a new dictionary where each key is prepended to its corresponding tuples then it flattens the result into a single list using a list comprehension.

Python
d = {'Gfg': [(5, 6, 7), (1, 3), (6, )],      'is': [(5, 5, 2, 2, 6)],      'best': [(7,), (9, 16)]}    # using dictionary comprehension to prepend key to each tuple p_dict = {k: [(k, *t) for t in v] for k, v in d.items()}   # flattening the result res = [i for sublist in p_dict.values() for i in sublist]  print("The converted tuple list : " + str(res)) 

Output
The converted tuple list : [('Gfg', 5, 6, 7), ('Gfg', 1, 3), ('Gfg', 6), ('is', 5, 5, 2, 2, 6), ('best', 7), ('best', 9, 16)] 

Explanation:

  • {k: [(k, *t) for t in v] for k, v in d.items()} this line creates a list of tuples where each tuple is formed by prepending the key k to each tuple t in the list v. and the * operator is used to unpack the tuples.
  • [item for sublist in prepended_dict.values() for item in sublist] this list comprehension flattens the result by iterating over the values of the newly created dictionary (pre_dict) which are lists of tuples and adding each tuple to the final res list.


Next Article
Python - Convert List of Lists to Tuple of Tuples
author
manjeet_04
Improve
Article Tags :
  • Python
  • Python Programs
  • Python dictionary-programs
  • Python list-programs
Practice Tags :
  • python

Similar Reads

  • Convert Tuple Value List to List of Tuples - Python
    We are given a dictionary with values as a list of tuples and our task is to convert it into a list of tuples where each tuple consists of a key and its corresponding value. Note: Each key will appear with each value from the list of tuples. For example: We have a dictionary dict = {'Gfg' : [(5, ),
    4 min read
  • Python - Convert List of Lists to Tuple of Tuples
    Sometimes, while working with Python data, we can have a problem in which we need to perform interconversion of data types. This kind of problem can occur in domains in which we need to get data in particular formats such as Machine Learning. Let us discuss certain ways in which this task can be per
    8 min read
  • Convert List of Tuples to Dictionary Value Lists - Python
    The task is to convert a list of tuples into a dictionary where the first element of each tuple serves as the key and the second element becomes the value. If a key appears multiple times in the list, its values should be grouped together in a list. For example, given the list li = [(1, 'gfg'), (1,
    4 min read
  • Python | Convert list of tuples to list of list
    Converting list of tuples to list of lists in Python is a task where each tuple is transformed into list while preserving its elements. This operation is commonly used when we need to modify or work with the data in list format instead of tuples. Using numpyNumPy makes it easy to convert a list of t
    3 min read
  • Python - Convert List to Single valued Lists in Tuple
    Conversion of data types is the most common problem across CS domain nowdays. One such problem can be converting List elements to single values lists in tuples. This can have application in data preprocessing domain. Let's discuss certain ways in which this task can be performed. Input : test_list =
    7 min read
  • Convert List of Tuples to List of Strings - Python
    The task is to convert a list of tuples where each tuple contains individual characters, into a list of strings by concatenating the characters in each tuple. This involves taking each tuple, joining its elements into a single string, and creating a new list containing these strings. For example, gi
    3 min read
  • Python | Convert list of tuples into list
    In Python we often need to convert a list of tuples into a flat list, especially when we work with datasets or nested structures. In this article, we will explore various methods to Convert a list of tuples into a list. Using itertools.chain() itertools.chain() is the most efficient way to flatten a
    3 min read
  • Convert Set of Tuples to a List of Lists in Python
    Sets and lists are two basic data structures in programming that have distinct uses. It is sometimes necessary to transform a collection of tuples into a list of lists. Each tuple is converted into a list throughout this procedure, and these lists are subsequently compiled into a single, bigger list
    3 min read
  • 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
  • Convert list of strings to list of tuples in Python
    Sometimes we deal with different types of data types and we require to inter-convert from one data type to another hence interconversion is always a useful tool to have knowledge. This article deals with the converse case. Let's discuss certain ways in which this can be done in Python. Method 1: Con
    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