Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python zip lists into dictionary

# app.py

stocks = ['reliance', 'infosys', 'tcs']
prices = [2175, 1127, 2750]
dictionary = dict(zip(stocks, prices))
print(dictionary)
Comment

Dictionary convert 2 lists into a dictionary, use zip()

# convert 2 lists into a dictionary, use zip()

aa = [1, 2, 3]
bb = ["a", "b", "c"]

print(dict(zip(aa, bb)))
# {1: 'a', 2: 'b', 3: 'c'}
Comment

zip Lists to a Dictionary

cast_names = ["Barney", "Robin", "Ted", "Lily", "Marshall"]
cast_heights = [72, 68, 72, 66, 76]

cast = dict(zip(cast_names, cast_heights))
print(cast)

#The order of elements in this output may vary since dictionaries are unordered
>>>{'Lily': 66, 'Barney': 72, 'Marshall': 76, 'Ted': 72, 'Robin': 68}
Comment

PREVIOUS NEXT
Code Example
Python :: pyspark import f 
Python :: selenium python get innerhtml 
Python :: python cli parameter 
Python :: how to import login required in django 
Python :: how to add button in tkinter 
Python :: alias python in macbook 
Python :: python click buttons on websites 
Python :: pandas filter string contain 
Python :: numpy install with pip 
Python :: how to change window size in kivy python 
Python :: display cv2 image in jupyter notebook 
Python :: label encoder python 
Python :: pandas empty dataframe with column names 
Python :: input spaces seperated integers in python 
Python :: change the current working directory in python 
Python :: django add media 
Python :: tensorflow mnist dataset import 
Python :: plot function in numpy 
Python :: draw a line pygame 
Python :: how to install python3 on ubuntu 
Python :: python read file delete first line 
Python :: conda python 3.8 
Python :: how to generate a random number python 
Python :: how to get latitude and longitude from address in python 
Python :: django today date in template 
Python :: pandas drop empty columns 
Python :: how to save a dictionary to excel in python 
Python :: human readable time difference python 
Python :: install flake8 python 
Python :: python str replace specifiek index 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =