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!

[IP066] A New Translation

Jimmy Pesto Sr., the owner of Jimmy Pesto's Pizzeria, wants to make his menu accessible to a wider audience by translating it into a different language. To achieve this, he decides to use two dictionaries: one that maps menu items to their current translations and another that provides translations of these terms into a new language. By combining these dictionaries, he aims to create a final dictionary with the translated menu items in the new language.

The Problem

Write a function compose(f, g) that given two dictionaries of f and g returns a new dictionary h that is the result of composing f with g, that is, h(k) = g(f(k)). The new dictionary should contain all keys k that exist in f such that f(k) also exists as a key in g.

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

1 ≤ |f|, |g| ≤ 100       number of keys on both f and g

Example Function Calls Example Output
f = {"coffee":"cafe", "milk":"leite", "tea":"cha", "juice":"sumo"}
g = {"leite":"leche", "sumo":"zumo"}
h = compose(f,g)
print(sorted(list(h.items())))
[('juice', 'zumo'), ('milk', 'leche')]

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