I have a dictionary and a list
mylist=[('B',), ('D',), ('B', 'D'), ('B', 'J'), ('B', 'P'), ('B', 'M'), ('D', 'J'), ('D', 'P'), ('D', 'M'), ('J', 'P'), ('J', 'M'), ('P', 'M'), ('B', 'D', 'J'), ('B', 'D', 'P'), ('B', 'D', 'M')]
dict={'B': [1, 0, 1, 1], 'D': [1, 1, 0, 1], 'J': [0, 0, 1, 1], 'P': [1, 1, 0, 1], 'M': [1, 0, 0, 1]}
what i was trying to do is to sum up the dictionary value based on the list. My code is:
myresult=[]
for k,v in dict.items():
row=sum(v for k, v in dict.items() if k in mylist)
myresult.append(row)
What i got was [0,0,0,0,0]
The intended result was to sum individual items from dictionary based on mylist and return something like
[(1,0,1,1), (1,1,0,1), (2,1,1,2), xxxx]
Could anyone help ?