Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

how to convert multi list to dict

# Your Data list

names = ["john", "paul", "george", "ringo"]
job = ["guitar", "bass", "guitar", "drums"]
status = ["dead", "alive", "dead", "alive"]

dict_data = [{'name': name, 'job': job, 'status': status} for name,job,status in zip(names,jobs,statuses)]
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

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

2 liste to a dictionary

d = {}
for i in list1:
    for j in list2:
        d[i] = j
print d
Comment

2 liste to a dictionary


keys = tel.keys()
values = tel.values()

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 :: put in something meaning 
Python :: Pandas automatic allignment of columns 
Python :: run selenium webdriver without opening browser 
Python :: exterat pdf python 
Python :: what is quit block in python 
Python :: Run multiple functions at the same time 
Python :: 1045 uri solution 
Python :: plotly garden wing map 
Python :: number guessing game using tkinter python 
Python :: Print Multiple Variables 
Python :: plotly showing routes 
Python :: how to sort a list of lists in reverse order using the first parameter in python 
Python :: How to add an item from another set or other data structures (lists, dictionaries, and tuples) to a set by using the update() method. 
Python :: accessing list elements in python 
Python :: how to check columns with the numerical values 
Python :: calculate iou of two rectangles 
Python :: python linkedhashmap 
Python :: saving to PIL image to s3 
Python :: Joining String And Variable 
Python :: check true false in python 
Python :: change tag name using beautifulsoup python 
Python :: clear list in python 
Python :: pyPS4Controller usage 
Python :: Django-rest-framework-simplejwt.readthedocs.io 
Python :: Using iterable unpacking operator * with extend 
Python :: online python pseudo code writer python 
Python :: preventing players to make entry in the same block in a python tic tac toe game 
Python :: filter titlecase django 
Python :: when excel is loaded into python, numeric datatype changes to float 
Python :: how to draw play area for a game in python turtle 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =