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 :: python run exe with arguments 
Python :: tkinter maximize window 
Python :: pandas sample seed 
Python :: assigning multiple values 
Python :: keras auc without tf.metrics.auc 
Python :: How to convert ton to kg using python 
Python :: remove too short strings from a list python 
Python :: python detect color on screen 
Python :: error 401 unauthorized "Authentication credentials were not provided." 
Python :: float print format python 
Python :: python open dicom file 
Python :: python json parse 
Python :: create dataframe from csv and name columns pandas 
Python :: bulk file name changer in python 
Python :: python valeur de pi 
Python :: remove duplicate space in string in pytoon 
Python :: pandas sort values by multiple columns 
Python :: python get city name from IP 
Python :: confusion matrix heat map 
Python :: How to add card in trello API using python 
Python :: how to check if its later than python 
Python :: how do you count most frequent item in a list in python 
Python :: jinja len is undefined 
Python :: write muli line conditional statements in python 
Python :: how to create notification in python 
Python :: Remove the First Character From the String in Python Using the Slicing 
Python :: python pause 
Python :: save image url to png python 
Python :: python dictionary get keys with condition on value 
Python :: object.image.url email template django 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =