how to put a list of elements into a dictionary in python code example
Example 1: python save list items to dictionary
'''
Converting a list to dictionary with list elements as keys in dictionary
All keys will have same value
'''
dictOfWords = { i : 5 for i in listOfStr }
Example 2: convert two lists to a single dictionary python
key_list = ['red', 'green', 'blue']
value_list = [1, 2, 3]
my_dict = {}
for key in key_list:
for value in value_list:
my_dict[key] = value
value_list.remove(value)
break
print(my_dict)
Example 3: append in dictionary with matrix values
import numpy as np
a = np.array([[4, 3], [2, 1]])
b = np.array([[1, 2], [3, 4]])
print(a@b)