- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create Python dictionary from list of keys and values?
If L1 and L2 are list objects containing keys and respective values, following methods can be used to construct dictionary object.
Zip two lists and convert to dictionary using dict() function
>>> L1 = ['a','b','c','d'] >>> L2 = [1,2,3,4] >>> d = dict(zip(L1,L2)) >>> d {'a': 1, 'b': 2, 'c': 3, 'd': 4}
Using dictionary comprehension syntax
>>> L1 = ['a','b','c','d'] >>> L2 = [1,2,3,4] >>> d = {k:v for k,v in zip(L1,L2)} >>> d {'a': 1, 'b': 2, 'c': 3, 'd': 4}
- Related Articles
- Python – Limit the values to keys in a Dictionary List
- How to create Python dictionary with duplicate keys?
- How to get a list of all the keys from a Python dictionary?
- How to convert Python dictionary keys/values to lowercase?
- How to insert new keys/values into Python dictionary?
- Python – Create dictionary from the list
- Append Dictionary Keys and Values (In order ) in dictionary using Python
- Combining values from dictionary of list in Python
- How to access nested Python dictionary items via a list of keys?
- Python Program – Create dictionary from the list
- Python - Create a dictionary using list with none values
- How to get a list of all the values from a Python dictionary?
- C# program to get the List of keys from a Dictionary
- Python Extract specific keys from dictionary?
- Keys associated with Values in Dictionary in Python

Advertisements