

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- How to create Python dictionary with duplicate keys?
- How to get a list of all the keys from a Python dictionary?
- Python – Limit the values to keys in a Dictionary List
- Combining values from dictionary of list in Python
- How to convert Python dictionary keys/values to lowercase?
- Append Dictionary Keys and Values (In order ) in dictionary using Python
- How to insert new keys/values into Python dictionary?
- Python Extract specific keys from dictionary?
- Python – Create dictionary from the list
- C# program to get the List of keys from a Dictionary
- How to access nested Python dictionary items via a list of keys?
- How to create Python dictionary from the value of another dictionary?
- How to get a list of all the values from a Python dictionary?
- Python Program – Create dictionary from the list
- Keys associated with Values in Dictionary in Python
Advertisements