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 Two Lists into a Dictionary – Python

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

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’: ‘Delhi’}. We can do this using methods like zip, dictionary comprehension , itertools.starmap. Let’s implement these methods practically.

Using zip

Use zip to pair elements from two lists, where the first list provides the keys and second provides the values after that we convert the zipped object into a dictionary using dict() which creates key-value pairs.

Python
a = ["name", "age", "city"] b = ["Alice", 30, "New York"]  res = dict(zip(a, b)) print(res) 

Output
{'name': 'Alice', 'age': 30, 'city': 'New York'} 

Explanation:

  • zip(a, b) pairs each element from list a with the corresponding element from list b, creating tuples of key-value pairs.
  • dict() function is used to convert the zipped pairs into a dictionary where elements from a become the keys and elements from b become values

Using Dictionary Comprehension

Use dictionary comprehension to iterate over the pairs generated by zip(a, b), creating key-value pairs where elements from list a are the keys and elements from list b are the values. This creates the dictionary in a single concise expression.

Python
a = ["name", "age", "city"] b = ["Alice", 30, "New York"]  res = {key: value for key, value in zip(a, b)} print(res) 

Output
{'name': 'Alice', 'age': 30, 'city': 'New York'} 

Explanation:

  • Dictionary comprehension iterates over pairs generated by zip(a, b), where each pair consists of a key from list a and a value from list b.
  • For each pair the key-value pair is directly added to dictionary res in one concise expression.

Using a Loop

Iterate through both lists simultaneously using zip and for each pair, add the first element as the key and second as the value to the dictionary.

Python
a = ["name", "age", "city"] b = ["Alice", 30, "New York"]  res = {}  for k, v in zip(a, b):     res[k] = v  print(res) 

Output
{'name': 'Alice', 'age': 30, 'city': 'New York'} 

Explanation:

  • An empty dictionary res is created, and zip(a, b) is used to iterate through both lists yielding pairs of keys and values.
  • During each iteration, key from list “a” is added to the dictionary with its corresponding value from list “b”

Using itertools.starmap

Use itertools.starmap to apply a lambda function that takes two arguments (key and value) to each pair generated by zip(a, b). This creates key-value pairs and passes them directly into dict() to form dictionary.

Python
from itertools import starmap  a = ["name", "age", "city"] b = ["Alice", 30, "New York"]  res = dict(starmap(lambda k, v: (k, v), zip(a, b))) print(res) 

Output
{'name': 'Alice', 'age': 30, 'city': 'New York'} 

Explanation:

  • starmap applies a lambda function to each pair from zip(a, b), where each pair consists of a key and a value.
  • lambda function returns the key-value pair (k, v) and dict() converts the results into a dictionary.

Related Articles:

  • zip() in Python
  • Python Dictionary Comprehension
  • Python – Itertools.starmap()
  • Python Lambda Functions


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

Similar Reads

  • Convert a list of Tuples into Dictionary - Python
    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 p
    3 min read
  • 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 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
  • 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
  • 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
  • How To Convert Python Dictionary To JSON?
    In Python, a dictionary stores information using key-value pairs. But if we want to save this data to a file, share it with others, or send it over the internet then we need to convert it into a format that computers can easily understand. JSON (JavaScript Object Notation) is a simple format used fo
    7 min read
  • How to Create a Dictionary in Python
    The task of creating a dictionary in Python involves storing key-value pairs in a structured and efficient manner, enabling quick lookups and modifications. A dictionary is an unordered, mutable data structure where each key must be unique and immutable, while values can be of any data type. For exa
    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
  • How to convert NumPy array to dictionary in Python?
    The following article explains how to convert numpy array to dictionary in Python. Array in Numpy is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers. In Numpy, number of dimensions of the array is called rank of the array. A tuple of integers givi
    3 min read
  • How to convert a MultiDict to nested dictionary using Python
    A MultiDict is a dictionary-like object that holds multiple values for the same key, making it a useful data structure for processing forms and query strings. It is a subclass of the Python built-in dictionary and behaves similarly. In some use cases, we may need to convert a MultiDict to a nested d
    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