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!
Jimmy Pesto Jr., always looking to one-up his rival restaurant, decides to experiment with a unique way of organizing the menu. He wants to create a reversed version of the menu where the prices are the keys, and the corresponding menu items are the values, so that he can quickly look up menu items based on their prices instead of their names.
Write a function swap(menu) that given a dictionary menu with string keys representing menu items and integer values representing prices, returns a new reverse dictionary where the new keys are the values and their new values are their correspondent old keys. It is guaranteed that there will be no repeated values on the input.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ |menu| ≤ 100 | number of items on the menu |
Example Function Calls | Example Output |
menu1 = {"coffee":60, "croissant":120, "donut":100, "burger":400} new_menu1 = swap(menu1) print(sorted(list(new_menu1.items()))) menu2 = {"one":"um", "two":"dois", "three":"tres", "four":"quatro"} new_menu2 = swap(menu2) print(sorted(list(new_menu2.items()))) |
[(60, 'coffee'), (100, 'donut'), (120, 'croissant'), (400, 'burger')] [('dois', 'two'), ('quatro', 'four'), ('tres', 'three'), ('um', 'one')] |