Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

create dictionary python from two lists

>>> keys = ['a', 'b', 'c']
>>> values = [1, 2, 3]
>>> dictionary = dict(zip(keys, values))
>>> print(dictionary)
{'a': 1, 'b': 2, 'c': 3}
Comment

convert 2 lists to a dictionary in python

""" How to convert 2 lists into a dictionary in python """
# list used for keys in dictionary
students = ["Angela", "James", "Lily"]

# list of values
scores = [56, 76, 98]

# convert lists to dictionary
student_scores = dict(zip(students, scores))

# print the dictionary
print(student_scores)

""" result should be
student_scores: -{
        Angela: 56,
        James: 76,
        Lily: 98
    },
"""
Comment

Convert two lists into a dictionary in Python

>>> students = ["Cody", "Ashley", "Kerry"]
>>> grades = [93.5, 95.4, 82.8]
>>> {s: g for s, g in zip(students, grades)}
{'Cody': 93.5, 'Ashley': 95.4, 'Kerry': 82.8}
Comment

create dict from two lists

keys = ['a', 'b', 'c']
values = [1, 2, 3]
dictionary = dict(zip(keys, values))
Comment

make dict from 2 lists

keys = ['a', 'b', 'c']
values = [1, 2, 3]
dictionary = dict(zip(keys, values))
print(dictionary) # {'a': 1, 'b': 2, 'c': 3}
Comment

create a dict from two lists

zip_iterator = zip(keys_list, values_list)
Comment

dictionary from two list

feat_dic = dict(zip(X.columns, feat_imp))
Comment

convert 2 lists into dictionary

# convert 2 list into dictionary
a = ['gsw','lakers','clippers']
b = [1,2,3]
my_dict = dict(zip(a,b))
print(my_dict)					# {'gsw': 1, 'lakers': 2, 'clippers': 3}
Comment

python two list into dictinaray

index = [1, 2, 3]
languages = ['python', 'c', 'c++']

dictionary = dict(zip(index, languages))
print(dictionary)
Comment

PREVIOUS NEXT
Code Example
Python :: find common elements in two lists python 
Python :: pandas drop unnamed columns 
Python :: python loop through all folders and subfolders 
Python :: window size cv2 
Python :: python date add days 
Python :: how to make a custom icon for pygame 
Python :: displaying flash message django 
Python :: check python version mac 
Python :: python find and replace string in file 
Python :: update numpy in python 
Python :: add seconds to datetime python 
Python :: export image python 
Python :: python reload file if changed 
Python :: sklearn.utils.bunch to dataframe 
Python :: selenium refresh page python 
Python :: read .dat python 
Python :: verify django has been installed 
Python :: timeout exception in selenium python 
Python :: python: remove duplicate in a specific column 
Python :: python delete none from list 
Python :: get current date and time with python 
Python :: How to increase text size tkinter 
Python :: return count of unique values pandas 
Python :: plot roc curve for neural network keras 
Python :: pandas - from umeric to string 
Python :: make y axis start at 0 python 
Python :: python write to command prompt 
Python :: django add media 
Python :: array of random integers python 
Python :: python messagebox 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =