I have a dictionary such as:
d = {'a':[0,0], 'b':[0,0], 'c':[0,1], 'd':[1,1]}
There's an order on the values, basically the lexicographic one, such that [0, 0] < [0,1] < [1,1]
.
I'm interested in retrieving the keys whose values are minimal according to this order. In this case the desired result is:
result = ['a', 'b']
I can do this by (1) getting the values of the dict, (2) converting it to a list L, (3) sorting L with:
L.sort(key = str),
then (4) getting the minimal element m of the sorted L, and finally (5) retrieving the keys whose values are m.
I can think of other variations of this procedure, but they all involve going through the dictionary and comparing things, and they're all perhaps too convoluted.
My question is if there's some simpler, more elegant (and more efficient) way of doing this. Should I be using a different data structure instead of a dictionary in the first place?