I have a dictionary in which keys and values are to be swapped. For eg:
dic = {"indianapolis":"indiana", "columbus":"ohio", "jackson":"mississippi",
"phoenix":"arizona"}
Output should be:
{"indiana":"indianapolis", "ohio":"columbus", "mississippi":"jackson",
"arizona":"phoenix"}
Here is what i tried but the constraints are that only sorted()
, split()
functions should be used and no other built-in function should be used (like keys()
, values()
, items()
,lambda
). Not really sure how to proceed further. Can someone help ? I am new to dictionaries.
def interchange(input_dict):
temp = {}
dic = input_dict
for i in dict:
temp[i[1]] = i[0]
return temp_dic