i am struggling with this for loop. I want to update the nested dictionary's value with the list. the following works, but I would like to use for loop to condense the code. "status" is a nested dictionary that has outer key "A" and "B", and binary_list[] just all 1's.
Trucks = ["A", "B"]
Days= ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"]
requests={"A": {"Monday":0, "Tuesday":0, "Wednesday":0, "Thursday":0
"Friday":0, "Saturday":0, "Sunday":0},
"B": {"Monday":0, "Tuesday":0, "Wednesday":0, "Thursday":0,
"Friday":0, "Saturday":0, "Sunday":0}}
binary_list=[1,1,1,1,1,1,1,1,1,1,1,1,1,1]
status["A"]["Monday"]=binary_list[0]
status["A"]["Tuesday"]=binary_list[1]
status["A"]["Wednesday"]=binary_list[2]
status["A"]["Thursday"]=binary_list[3]
status["A"]["Friday"]=binary_list[4]
status["A"]["Saturday"]=binary_list[5]
status["A"]["Sunday"]=binary_list[6]
status["B"]["Monday"]=binary_list[7]
status["B"]["Tuesday"]=binary_list[8]
status["B"]["Wednesday"]=binary_list[9]
status["B"]["Thursday"]=binary_list[10]
status["B"]["Friday"]=binary_list[11]
status["B"]["Saturday"]=binary_list[12]
status["B"]["Sunday"]=binary_list[13]
what I tried:
for truck in Trucks:
for day in Days:
requests[truck][day]=[j for j in binary_list]
this will produce 14 1's in a list as the value of each of the day. I understand why this happens. it's because of the 2 for loops, so I figured I need a nested dictionary comprehenssions to make everything into one line. I am not sure that is correct, but with my limited knowledge that seems to be the right direction. my questions is how do I do that? would someone please help. thanks again for your time.