I have a dictionary
my_dict = {'name':['a','b','c','d','e'],'c1':[0,0,1,2,0],'c2':[3,0,2,1,2],'c3':[1,2,3,4,5]}
I want to sort the dictionary based on the value of c1
and c2
. How can I do that?
I.e. Priority to sort the dict is using C1 but if C1 has to same values like c1[0] and c1[1] at that time it short the data based on C2 data.
I have tried below but getting error:
c1_list = count_dict.get('c1')
c1_list.sort(reverse=True)
index_map = {v: i for i, v in enumerate(c1_list)}
print sorted(my_dict.items(), key=lambda pair: index_map[pair[0]])
Expected Output:
{'name':['d','c','a','e','b'],'c1':[2,1,0,0,0],'c2':[1,2,3,2,0],'c3':[4,3,1,5,2]}