Stuck defining composition function in python
<p>input: two functions f and g, represented as dictionaries, such that g â¦ f exists. output: dictionary that represents the function g â¦ f. 
example: given f = {0:âaâ, 1:âbâ} and g = {âaâ:âappleâ, âbâ:âbananaâ}, return {0:âappleâ, 1:âbananaâ}.</p>

<p>The closest to the correct answer I have is with {i:g[j] for i in f for j in g} which outputs {0: 'apple', 1: 'apple'}. What am I doing wrong?</p>

<p>You need to just iterate over one dict <code>f</code>, and in the comprehension, replace the value of f with the value of <code>g</code>  </p>

<pre><code>f = {0:'a', 1:'b'}
g = {'a':'apple', 'b': 'banana'}
new_dict = {k: g[v] for k, v in f.items()}
# Value of new_dict = {0: 'apple', 1: 'banana'}
</code></pre>

python composition