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 :: swap in python 
Python :: skimage local threshold 
Python :: django jinja else if template tags 
Python :: pandas df describe() 
Python :: open file dialog on button click pyqt5 
Python :: python scipy moving average 
Python :: how to read linux environment variable in python 
Python :: matplotlib list backend 
Python :: python logistic function 
Python :: install turtle python mac 
Python :: sns boxplot 
Python :: rotate 2d array 
Python :: Python3 seconds to datetime 
Python :: pandas not a time nat 
Python :: time.sleep() python 
Python :: list pop python 
Python :: PY | websocket - client 
Python :: python get number of arguments of a function 
Python :: numpy indexing arrays 
Python :: how to python 
Python :: string upper lower count python 
Python :: how to find a prime number 
Python :: If elif else 
Python :: file open in python 
Python :: Word2Vec 4.0 Gensim model python dataframe 
Python :: add a tuple to a dictionary python 
Python :: axios django post data 
Python :: get the path of a module in python 
Python :: re python3 
Python :: pca 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =