two list to dictionary python

two list to dictionary python

Hi,

I have two lists and I want to covert it into dictionary. I want to create keys from one list and values from another list.

How I can convert two list to dictionary python?

Thanks

View Answers

July 18, 2021 at 3:43 PM

Hi,

It is possible in Python and you use the zip function to achieve this.

Here is sample example code:

keys = ['ID', 'name', 'country']
values = ['C001', "Ravi", 'India']

dict = dict(zip(keys, values))
print(dict)

Above code will give you following output:

>>> keys = ['ID', 'name', 'country']
>>> values = ['C001', "Ravi", 'India']
>>> 
>>> dict = dict(zip(keys, values))
>>> print(dict)
{'ID': 'C001', 'name': 'Ravi', 'country': 'India'}
>>>

Thanks


July 18, 2021 at 3:43 PM

Hi,

Check more tutorials at:

Thanks









Related Tutorials/Questions & Answers:
two list to dictionary python
two list to dictionary python  Hi, I have two lists and I want to covert it into dictionary. I want to create keys from one list and values from another list. How I can convert two list to dictionary python? Thanks   
How to append a dictionary to a list in Python
is to add the dictionary into the list. How I can achieve this? How to append a dictionary to a list in Python? Thanks   Hi, Here is the simple example...How to append a dictionary to a list in Python  Hi, I have a loop
Advertisements
How to return dictionary keys as a list in Python
How to return dictionary keys as a list in Python  Hi, I want to access the keys of dictionary as list in Python program. Here is dictionary data: word_dict = {1:"one", 2:"Two", 3:"Three", 4:"Four", 5:"Five", 6:"Six", 7
How to return dictionary keys as a list in Python
How to return dictionary keys as a list in Python  Hi, I want to access the keys of dictionary as list in Python program. Here is dictionary data: word_dict = {1:"one", 2:"Two", 3:"Three", 4:"Four", 5:"Five", 6:"Six", 7
Python sum dictionary values by key
Python sum dictionary values by key  Hi, In python we can easily... in key value pair. I have two dictionary with same keys and different numeric.... What is the code for Python sum dictionary values by key? Thanks
python sorted dictionary
python sorted dictionary  Hi, Is it possible to sort the dictionary in Python. I am trying to find examples of sorted dictionary in Python. Thanks
Python Dictionary
Python Dictionary - Create, Update, Access and Clear dictionary object... in Python. Let's get started with the Python Dictionary data structure. What is Python Dictionary? Dictionary is one of the data structure in Python which
How do you combine two dictionary values for common keys
? I want example code in Python. How do you combine two dictionary values...How do you combine two dictionary values for common keys  Hi, I have two dictionary and I want to combine the values based on the key in new
How to append dictionary to a list in loop
How to append dictionary to a list in loop  Hi, I have to write a program in Python for appending dictionary to list in for loop. I will be creating a new dictionary in the loop and then adding to the list. What is the best way
Convert dictionary to JSON Python
Converting dictionary object to JSON in Python program Dictionary is one... library. Consider the following dictionary: book_dict = {"name":"Python Book", "price":"100"} In the above code we are declaring a dictionary in Python
Convert dictionary to JSON Python
a dictionary in Python with two key and associated values. Now we want to convert...Converting dictionary object to JSON in Python program Dictionary is one...() is used to convert dictionary object to JSON string in Python
Add a new item to a dictionary in Python
to a python dictionary? Share me example for adding a new item to a dictionary in Python. Thanks   Hi, Suppose you have following dictionary: days...Add a new item to a dictionary in Python  Hi, I have an dictionary
how to add data into dictionary in python
how to add data into dictionary in python  Hi, I have a python API that returns Python dictionary. It contains many values. Here is simple example...} I want to add DOB to this dictionary object. how to add data into dictionary
how to access python dictionary elements
how to access python dictionary elements  Hi, I am new to Python... dictionary object. What is code for accessing elements from Python dictionary? How to access python dictionary elements? Thanks   Hello, Python
how to access python dictionary elements
how to access python dictionary elements  Hi, I am new to Python... dictionary object. What is code for accessing elements from Python dictionary? How to access python dictionary elements? Thanks   Hello, Python
adding one element in dictionary python
adding one element in dictionary python  Hi, I am looking for code for adding one element in dictionary python. Thanks   Hi, Here... more tutorials at: Python Tutorials Thanks
ModuleNotFoundError: No module named 'plover-python-dictionary'
ModuleNotFoundError: No module named 'plover-python-dictionary'  Hi...: No module named 'plover-python-dictionary' How to remove the ModuleNotFoundError: No module named 'plover-python-dictionary' error? Thanks  
ModuleNotFoundError: No module named 'plover-python-dictionary'
ModuleNotFoundError: No module named 'plover-python-dictionary'  Hi...: No module named 'plover-python-dictionary' How to remove the ModuleNotFoundError: No module named 'plover-python-dictionary' error? Thanks  
How to add a new item to a dictionary in Python
an existing dictionary in Python. I want to add new item to it. How to add a new item to a dictionary in Python? Thanks   Hi, Python dictionary is very... following dictionary: book_dict = {"name":"Python Book", "price":"100"} Now you have
How to convert Python dictionary to JSON?
How to convert Python dictionary to JSON? Python example to create dictionary... is the program to convert dictionary to JSON in Python: ADS_TO_REPLACE_2 Here is complete example of converting the Python dictionary to JSON: import json
Read JSON file into Python dictionary
How to Read JSON file into Python dictionary? This is quick guide for developers to read a json file into Python dictionary object. JSON is most proffered..." } Following program is used read the data into Python dictionary
Read JSON file into Python dictionary
How to Read JSON file into Python dictionary? This is quick guide for developers to read a json file into Python dictionary object. JSON is most proffered... into dictionary object in Python. Python provides json.load() function
How do I convert a dictionary to a JSON object in Python?
How do I convert a dictionary to a JSON object in Python?  Hi, I... is returning the dictionary object. Now our requirement is to convert it to JSON... the dictionary object to JSON data. I want to use any pre-built API. Share me some
python merge two dictionaries add values
python merge two dictionaries add values  Hi, In Python I have two dictionaries with same keys. I want to merge the two dictionaries and add the values (int values) into the merged dictionary. For example student marks in three
Merge two list into a single list
and the mergelist funtion merge the two lists into a single list. Code: # include...Description: This example demonstrate how to merge two lists into a single list. Here you find mainly three function. The insertnode function makes node
Version of com.clearnlp>clearnlp-dictionary dependency
List of Version of com.clearnlp>clearnlp-dictionary dependency
Version of com.hynnet>jradius-dictionary dependency
List of Version of com.hynnet>jradius-dictionary dependency
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
list of all months between two dates in java
list of all months between two dates in java  Hi, I want to get list of all months with year between two dates. How to do this in Java? Thanks   Hi, This is the example code which can be used: package test.app
Split a list into two equal size list
data into list another for printing the list and last one for split of list... node **q, int n) { struct node *temp; int i =1; temp = p; while( i < n) { temp = temp->link; i++; } *q = temp->link
Multiplication of two polynomials using linked list in java
Multiplication of two polynomials using linked list in java  I am doing a program "Multiplication of two polynomials using linked list in java... for polynomial linked list import java.util.Scanner; class Node { public int
Version of com.hynnet>jradius-dictionary-min dependency
List of Version of com.hynnet>jradius-dictionary-min dependency
ModuleNotFoundError: No module named 'dictionary'
ModuleNotFoundError: No module named 'dictionary'  Hi, My Python...;dictionary' error? Thanks   Hi, In your python environment you have to install padas library. You can install dictionary python
Dictionary class
Dictionary class  hello,, What is the Dictionary class?   hii,,ADS_TO_REPLACE_1 The Dictionary class provides the capability to store key-value pairs
How to use list in for loop in Python
How to use list in for loop in Python  Hi, I have list in Python and I want to list down all the items using for loop. How to use list in for loop in Python? Thanks
How do you sum a dictionary
How do you sum a dictionary  Hi, I want to sum the values of two dictionary based on keys. How do you sum a dictionary
How to get of lastmodified file list between two times in java?
How to get of lastmodified file list between two times in java?  Hi, here is a code that list the last modified files in a directory between two dates. This is working well but is it possible to do the same thing between two
Java dictionary class
Java dictionary class  What is the Dictionary class
ModuleNotFoundError: No module named 'italian-dictionary'
italian-dictionary python with following command: pip install italian-dictionary After the installation of italian-dictionary python library...ModuleNotFoundError: No module named 'italian-dictionary'  Hi, My
ModuleNotFoundError: No module named 'italian-dictionary'
italian-dictionary python with following command: pip install italian-dictionary After the installation of italian-dictionary python library...ModuleNotFoundError: No module named 'italian-dictionary'  Hi, My
ModuleNotFoundError: No module named 'italian-dictionary'
italian-dictionary python with following command: pip install italian-dictionary After the installation of italian-dictionary python library...ModuleNotFoundError: No module named 'italian-dictionary'  Hi, My
ModuleNotFoundError: No module named 'nanoid-dictionary'
-dictionary python with following command: pip install nanoid-dictionary After the installation of nanoid-dictionary python library, ModuleNotFoundError...ModuleNotFoundError: No module named 'nanoid-dictionary'  Hi, My
ModuleNotFoundError: No module named 'NlpToolkit-Dictionary'
install NlpToolkit-Dictionary python with following command: pip install NlpToolkit-Dictionary After the installation of NlpToolkit-Dictionary python...ModuleNotFoundError: No module named 'NlpToolkit-Dictionary'  Hi
ModuleNotFoundError: No module named 'pocket-dictionary'
-dictionary python with following command: pip install pocket-dictionary After the installation of pocket-dictionary python library, ModuleNotFoundError...ModuleNotFoundError: No module named 'pocket-dictionary'  Hi, My
ModuleNotFoundError: No module named 'versioned-dictionary'
versioned-dictionary python with following command: pip install versioned-dictionary After the installation of versioned-dictionary python library...ModuleNotFoundError: No module named 'versioned-dictionary'  Hi
ModuleNotFoundError: No module named 'volatile-dictionary'
volatile-dictionary python with following command: pip install volatile-dictionary After the installation of volatile-dictionary python library...ModuleNotFoundError: No module named 'volatile-dictionary'  Hi, My
ModuleNotFoundError: No module named 'yandex-dictionary'
-dictionary python with following command: pip install yandex-dictionary After the installation of yandex-dictionary python library, ModuleNotFoundError...ModuleNotFoundError: No module named 'yandex-dictionary'  Hi, My
ModuleNotFoundError: No module named 'yandex-dictionary'
-dictionary python with following command: pip install yandex-dictionary After the installation of yandex-dictionary python library, ModuleNotFoundError...ModuleNotFoundError: No module named 'yandex-dictionary'  Hi, My
ModuleNotFoundError: No module named 'yandex-dictionary'
-dictionary python with following command: pip install yandex-dictionary After the installation of yandex-dictionary python library, ModuleNotFoundError...ModuleNotFoundError: No module named 'yandex-dictionary'  Hi, My
ModuleNotFoundError: No module named 'Yuci-Dictionary'
'Yuci-Dictionary' error? Thanks   Hi, In your python... python with following command: pip install Yuci-Dictionary After the installation of Yuci-Dictionary python library, ModuleNotFoundError: No module

Ads