Question: Recall the following exercise from Homework 3. Write a function inverter(D) which takes a dictionary D and returns a new dictionary with the keys and

Recall the following exercise from Homework 3. Write a function inverter(D) which takes a dictionary D and returns a new dictionary with the keys and values swapped. inverter({1:a,2:b,3::c}){a:1,b:2,c:3}inverter({1:a,2:a,3:bb}){a:[1,2],b:3} Consider the following attempt to implement the inverter function: def inverter (D): result ={} for k, v in D: if v not in result: result [v]=k else: if type(result [v])= List: result [v]= result [v] append (k) else: result[v]=[ result [v],k] return result
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
