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!

[IP064] Dish Renaming

Linda Belcher, the co-owner of Bob's Burgers, believes that a catchy name can make any dish more appealing. She wants to rename one specific item on the restaurant's menu. The menu is represented as a dictionary where the keys are the names of menu items and the values are their prices. Linda wants to replace the name of one existing item with a new, more exciting name while keeping its price unchanged.

The Problem

Write a function rename(menu, old_name, new_name) that given a dictionary menu with string keys representing menu items and integer values representing prices, changes the entry with key=old_name to key=new_name, that is, deletes the entret with the key old_name and create an entry with new_name and the same price. If old_key does not exist, the menu should remain unchanged.

Constraints

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
menu = {"coffee":60, "croissant":120, "donut":100, "burger":400}
rename(menu, "croissant", "frenchy")
print(sorted(list(menu.items())))
rename(menu, "donut", "roundy")
print(sorted(list(menu.items())))
rename(menu, "icecream", "icy")
print(sorted(list(menu.items())))
[('burger', 400), ('coffee', 60), ('donut', 100), ('frenchy', 120)]
[('burger', 400), ('coffee', 60), ('frenchy', 120), ('roundy', 100)]
[('burger', 400), ('coffee', 60), ('frenchy', 120), ('roundy', 100)]

Introduction to Programming (CC1024)
DCC/FCUP - University of Porto