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 - Dictionary Values Mapped Summation
Next article icon

Python – Mapping Key Values to Dictionary

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

We are given two list and we need to map key to values of another list so that it becomes dictionary. For example, we are given two list k = [‘a’, ‘b’, ‘c’] and v = [1, 2, 3] we need to map the keys of list k to the values of list v so that the resultant output should be {‘a’: 1, ‘b’: 2, ‘c’: 3}.

Using zip()

zip() function pairs elements from two lists allowing us to create a dictionary using dict(zip(keys, values)) where each key gets mapped to its corresponding value.

[GFGTABS]
Python

k = ['a', 'b', 'c'] v = [1, 2, 3]  d = dict(zip(k, v)) print(d) 


[/GFGTABS]

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

Explanation:

  • zip(k, v) function pairs elements from lists k and v into tuples and dict() converts these tuples into key-value pairs in dictionary d.
  • Resulting dictionary d is {‘a’: 1, ‘b’: 2, ‘c’: 3}, where each key from k is mapped to its corresponding value in v.

Using Dictionary Comprehension

Dictionary comprehension iterates through the indices of key list and maps each key to its corresponding value from value list.

[GFGTABS]
Python

k = ['a', 'b', 'c'] v = [1, 2, 3]  d = {k[i]: v[i] for i in range(len(k))} print(d) 


[/GFGTABS]

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

Explanation:

  • This dictionary comprehension iterates over indices of the k list and assigns each key from k to its corresponding value from v using k[i]: v[i].
  • It ensures that mapping is created efficiently without requiring external functions making it a straightforward approach when both lists have same length.

Using dict.fromkeys()

dict.fromkeys(k, v) creates a dictionary where all keys in k are mapped to the same single value v, not individual values from list. It is useful when assigning a default value to multiple keys.

[GFGTABS]
Python

k = ['a', 'b', 'c'] d = 0  d = dict.fromkeys(k, d) print(d) 


[/GFGTABS]

Output
{'a': 0, 'b': 0, 'c': 0} 

Explanation: dict.fromkeys(k, d) creates a dictionary where each key from the list k is assigned the same value d (which is 0 in this case).

Using map() and dict()

zip(k, v) function pairs corresponding elements from the key and value lists, which map() processes into key-value tuples dict() function then converts these tuples into a dictionary effectively mapping keys to values.

[GFGTABS]
Python

k = ['a', 'b', 'c'] v = [1, 2, 3]  d = dict(map(lambda k, v: (k, v), k, v)) print(d) 


[/GFGTABS]

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

Explanation:

  • map() function pairs each key in k with its corresponding value in v using a lambda function.
  • dict() function then converts the mapped pairs into a dictionary.

Related Article:

  • zip()
  • dictionary
  • Dictionary comprehension


Next Article
Python - Dictionary Values Mapped Summation
author
manjeet_04
Improve
Article Tags :
  • Python
  • Python Programs
  • Python list-programs
Practice Tags :
  • python

Similar Reads

  • Python Print Dictionary Keys and Values
    When working with dictionaries, it's essential to be able to print their keys and values for better understanding and debugging. In this article, we'll explore different methods to Print Dictionary Keys and Values. Example: Using print() Method [GFGTABS] Python my_dict = {'a': 1, 'b'
    2 min read
  • Add a key value pair to Dictionary in Python
    The task of adding a key-value pair to a dictionary in Python involves inserting new pairs or updating existing ones. This operation allows us to expand the dictionary by adding new entries or modify the value of an existing key. For example, starting with dictionary d = {'key1': 'geeks', 'key2': 'f
    3 min read
  • Python - Dictionary Values Mapped Summation
    Given a dictionary with a values list, our task is to extract the sum of values, found using mappings. Input : test_dict = {4 : ['a', 'v', 'b', 'e'], 1 : ['g', 'f', 'g'], 3 : ['e', 'v']}, map_vals = {'a' : 3, 'g' : 8, 'f' : 10, 'b' : 4, 'e' : 7, 'v' : 2} Output : {4: 16, 1: 26, 3: 9} Explanation : "
    6 min read
  • Python - Cross mapping of Two dictionary value lists
    GIven two dictionaries with list values, perform mapping of keys of first list with values of other list, by checking values-key linkage. Input : test_dict1 = {"Gfg" : [4, 10], "Best" : [8, 6], "is" : [9, 3]}, test_dict2 = {6 : [15, 9], 8 : [6, 3], 7 : [9, 8], 9 : [10, 11]} Output : {'Best': [6, 3,
    6 min read
  • How to Add Values to Dictionary in Python
    The task of adding values to a dictionary in Python involves inserting new key-value pairs or modifying existing ones. A dictionary stores data in key-value pairs, where each key must be unique. Adding values allows us to expand or update the dictionary's contents, enabling dynamic manipulation of d
    3 min read
  • Set from Dictionary Values - Python
    The task is to extract unique values from a dictionary and convert them into a set. In Python, sets are unordered collections that automatically eliminate duplicates. The goal is to extract all the values from the dictionary and store them in a set. For example, given a dictionary like d = {'A': 4,
    3 min read
  • Python - Value length dictionary
    Sometimes, while working with a Python dictionary, we can have problems in which we need to map the value of the dictionary to its length. This kind of application can come in many domains including web development and day-day programming. Let us discuss certain ways in which this task can be perfor
    4 min read
  • Python Update Dictionary Value by Key
    A Dictionary in Python is an unordered collection of key-value pairs. Each key must be unique, and you can use various data types for both keys and values. Dictionaries are enclosed in curly braces {}, and the key-value pairs are separated by colons. Python dictionaries are mutable, meaning you can
    3 min read
  • Python Dictionary Add Value to Existing Key
    The task of adding a value to an existing key in a Python dictionary involves modifying the value associated with a key that is already present. Unlike adding new key-value pairs, this operation focuses on updating the value of an existing key, allowing us to increment, concatenate or otherwise adju
    2 min read
  • Get Python Dictionary Values as List - Python
    We are given a dictionary where the values are lists and our task is to retrieve all the values as a single flattened list. For example, given the dictionary: d = {"a": [1, 2], "b": [3, 4], "c": [5]} the expected output is: [1, 2, 3, 4, 5] Using itertools.chain()itertools.chain() function efficientl
    2 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