1>>> a = {0:'000000',1:'11111',3:'333333',4:'444444'}
2>>> a.keys()
3[0, 1, 3, 4]
4>>> sorted(a.keys())
5[0, 1, 3, 4]
6>>> reversed(sorted(a.keys()))
7<listreverseiterator object at 0x02B0DB70>
8>>> list(reversed(sorted(a.keys())))
9[4, 3, 1, 0]
1def inverse_dict(my_dict):
2 """
3 the func get a dictinary and reverse it, the keys become values and the values become keys.
4 :param my_dict: the dictinary that need to be reversed.
5 :return: a VERY pretty dictionary.
6 """
7 result_dict = {}
8 for key, value in my_dict.items():
9 if not value in result_dict.keys():
10 result_dict[value] = []
11 result_dict[value].append(key)
12 return result_dict, print(result_dict)