'Computing the average rating of each food from the lists:
food = ['apple', 'banana', 'pear', 'apple', 'orange', 'pear'] rating = [5, 4, 3, 3, 2, 4]
I have to group each fruit first, and calculate the average rating for that fruit only so my answer should be this: [('apple, 4), ('banana', 4), ('pear', 3.5), ('orange',2)]
i.e apple has 2 ratings, 5 and 3 so mean is 4. how can i do the code in python 3.
I am doing dict(Counter(food)) to get unique values of food, but then how do i take those corresponding rating and make another list with food name and rating together.
Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
