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 dictionary items to values
Next article icon

Python Convert Dictionary to List of Values

Last Updated : 07 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Python has different types of built-in data structures to manage your data. A list is a collection of ordered items, whereas a dictionary is a key-value pair data. Both of them are unique in their own way. In this article, the dictionary is converted into a list of values in Python using various concepts and methods. Here, we will see how we can convert a dictionary into a list of values in Python.

Convert Dictionary to List of Values in Python

Below are some of the ways by which we can convert a dictionary to a list of values in Python:

  1. Using for loop
  2. Using items() Function
  3. Using Zip Function

Convert Dictionary to List Using For Loop

The below method converts dictionary data into a list list_of_data using a for loop. It iterates through the keys of the dictionary, retrieves the corresponding values using data.get(key), and appends a list containing the key-value pair to the list_of_data list.

Python
# initial dictionary data = {1: "Gaurav", 2: "Sanket", 3: "Anjali", 4: "Priyanka"}  # empty list to store key-value pairs list_of_data = []  # iterate through dictionary for key in data:     # append key-value pair to the list     list_of_data.append([key, data.get(key)])  # print the resulting list print(type(list_of_data)) print(list_of_data) 

Output
<type 'list'> [[1, 'Gaurav'], [2, 'Sanket'], [3, 'Anjali'], [4, 'Priyanka']]

Python Convert Dictionary to List Using .items() Function

The below method uses the items() method to convert a dictionary (data) into a list (list_of_data), containing key-value pairs. The resulting list is then printed, demonstrating the transformation of dictionary data into a list of values.

Python
# initial dictionary data = {1: &quot;Gaurav&quot;, 2: &quot;Sanket&quot;, 3: &quot;Anjali&quot;, 4: &quot;Priyanka&quot;}  # convert dict items into list list_of_data = list(data.items())  # printing the resulting list print(type(list_of_data)) print(list_of_data) 

Output
<type 'list'> [(1, 'Gaurav'), (2, 'Sanket'), (3, 'Anjali'), (4, 'Priyanka')]

Python Dictionary to List Using Zip Function

Using the zip function, the provided code converts a dictionary (data) into a list (list_of_data) by combining keys and values into tuples and then converting them into a list. This method showcases the demonstration of the zip function for creating a list of values from a dictionary.

Python
# initial dictionary data = {1: &quot;Gaurav&quot;, 2: &quot;Sanket&quot;, 3: &quot;Anjali&quot;, 4: &quot;Priyanka&quot;}  # Zip tuple of kays &amp; values into list list_of_data = list(zip(data.keys(), data.values()))  # printing the resulting list print(type(list_of_data)) print(list_of_data) 

Output
<type 'list'> [(1, 'Gaurav'), (2, 'Sanket'), (3, 'Anjali'), (4, 'Priyanka')]

Conclusion

In conclusion, various methods have been explored for converting a dictionary to a list of values in Python. Whether using for loops, the .items() function, list comprehension, the zip function, or the map function, each approach offers a way to achieve the conversion. Developers can choose the method that best fits their preferences and coding style, enhancing flexibility in managing and manipulating data structures.


Next Article
Python - Convert dictionary items to values
author
gaurav7165
Improve
Article Tags :
  • Python
  • Python Programs
  • python
Practice Tags :
  • python
  • 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 - Convert dictionary items to values
    Sometimes, while working with Python dictionary, we can have a problem in which we need to convert all the items of dictionary to a separate value dictionary. This problem can occur in applications in which we receive dictionary in which both keys and values need to be mapped as separate values. Let
    3 min read
  • Convert Matrix to Dictionary Value List - Python
    We are given a matrix and the task is to map each column of a matrix to customized keys from a list. For example, given a matrix li = [[4, 5, 6], [1, 3, 5], [3, 8, 1], [10, 3, 5]] and a list map_li = [4, 5, 6], the goal is to map the first column to the key 4, the second column to the key 5, and the
    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 - Add Values to Dictionary of List
    A dictionary of lists allows storing grouped values under specific keys. For example, in a = {'x': [10, 20]}, the key 'x' maps to the list [10, 20]. To add values like 30 to this list, we use efficient methods to update the dictionary dynamically. Let’s look at some commonly used methods to efficien
    3 min read
  • Python - Convert key-values list to flat dictionary
    We are given a list that contains tuples with the pairs of key and values we need to convert that list into a flat dictionary. For example a = [("name", "Ak"), ("age", 25), ("city", "NYC")] is a list we need to convert it to dictionary so that output should be a flat dictionary {'name': 'Ak', 'age':
    3 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
  • Convert List of Named Tuples to Dictionary - Python
    We are given a list of named tuples we need to convert it into dictionary. For example, given a list li = [d("ojaswi"), d("priyank"), d("sireesha")], the goal is to convert it into a dictionary where each unique key maps to a list of its corresponding values, like {'Name': 'ojaswi'},{'Name': 'priyan
    3 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
  • 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
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