In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of November 30th
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #07 exercise sheet]
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
Gene Belcher, the musical genius from Bob's Burgers, is organizing the restaurant's inventory and wants to know how many times each ingredient appears in the inventory list. The ingredients are stored in a list of strings, and Gene wants to count the occurrences of each ingredient so he can better manage stock and plan recipes.
Write a function frequency(ingredients) that given a list ingredients of strings, creates a dictionary where the keys are ingredient names and the values are their frequency (number of occurrences) on the list.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ |ingredients| ≤ 100 | number of ingredients on the list |
Example Function Calls | Example Output |
ingredients = ["burger", "burger", "tea", "water", "burger", "tea", "juice"] fr = frequency(ingredients) print(sorted(list(fr.items()))) |
[('burger', 3), ('juice', 1), ('tea', 2), ('water', 1)] |