The following works fine:
from operator import itemgetter
d = { "a":(4,15), "c":(3,2), "b":(12,6) }
for k, v in sorted(d.items(), key=itemgetter(1)):
print k, v
This returns:
c (3, 2)
a (4, 15)
b (12, 6)
But I would like to sort by second element of v
: [15, 2, 6]
Get the impression for a dict
this is not possible. True?
I looked around, but cannot seem to find... sorting by v
means the order of items is important I see.