Quote:
|
Originally Posted by Dietrich
If you had made an English  utch dictionary, how could you convert that to a Dutch:English dictionary? Any ideas?
|
If you mean how do you change a dictionary from keys:items to items:keys, try this:
def reversedict(original_dict):
dict2 = {}
dict_list = original_dict.items()
for i in dict_list:
dict2[i[1]] = i[0]
return dict2
# Dict 1 is just for the purpose of example, you could feed this function
# Any dictionary.
dict1 = {1: 'a', 2: 'b', 3: 'c', 4: 'd'}
dict3 = reversedict(dict1)
print dict3