Answers for "how to put a list of elements into a dictionary in python"

1

convert two lists to a single dictionary python

#initialize lists

key_list = ['red', 'green', 'blue']
value_list = [1, 2, 3]

#convert lists

my_dict = {} 
for key in key_list: 
    for value in value_list: 
        my_dict[key] = value 
        value_list.remove(value) 
        break  
print(my_dict)
Posted by: Guest on January-04-2021
0

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)
# [[13 20]
#  [ 5  8]]
Posted by: Guest on June-12-2020

Code answers related to "how to put a list of elements into a dictionary in python"

Python Answers by Framework

Browse Popular Code Answers by Language