Home > Net >  adding list of items into the values of Dictionary
adding list of items into the values of Dictionary

Time:10-27

Let's say i have a list [10,9,8,7] and i have a my_dict {4:0, 3: 0, 2: 0 , 1 : 0}

I'm new to Python and I've tried researching how to go about this but I still could not find an answer. I want to add the list to the values of my_dict, how should I approach this?

my_list = [10,9,8,7]
my_dict = {4:0, 3: 0, 2: 0 , 1 : 0}

CodePudding user response:

Is this what you're looking for

for index, (key,value) in enumerate(my_dict.items()):
   my_dict[key] = my_list[index]
print(my_dict)
  • Related