I am very new to Python and programming, and am struggling to understand a problem. Any help is greatly appreciated.
I have a deque of values and categories:
deque([(3000.0, category1), (6000.0, category1), (8000.0, category2), (3000.0, category3), (7000.0, category3), (4500.0, category3)])
I am trying to use a dictionary to print the average of each value by category. For example, category1 = (3000 + 6000) / 2; category2 = 8000 / 1; category3 = (3000 + 7000 + 4500) / 3.
Is there a straightforward way to do this? So far, my only thought is to create a list of unique categories:
catetory_list = []
for i in deque:
if i[1] not in category_list:
category_list.append(i[1])
I think I am missing something important here, but can't seem to find the next step.
I found some similar issues here already, namely here and here, but I am struggling on how to make this fit for my question.