Suppose you have the following nested dictionary:
groceries = {
'tom': {
'apples': [1,0,1,0,1,0,1],
'lettuce': [1,0,0,1,1,0,0]
},
'andy': {
'oranges': [1,0,1,0,1,0,1],
'eggplant': [1,0,0,1,1,0,0],
'lettuce': [0,1,0,0,0,0,1]
}
}
Tom and Andy are professional grocery shoppers and go shopping every day. Each list is a result of how many of each product they purchased a particular day of the week. I would like to generate an output list that provides a sum of products purchased for each day of the week for each shopper. The only way I can think to solve this is to iterate using a nested for loop such as:
for k,v in groceries.items():
for i in v.items():
Is there a way to approach this that doesn't involve using a nested for-loop?