sort python dictionary with values of list by index of first one

35

li = [[1,4,7],[3,6,9],[2,59,8]]
li.sort(key=lambda x: int(x[0]))
>>> collections.OrderedDict(sorted(a.iteritems(), key=lambda (k,v):v[0], reverse=True))
OrderedDict([('key2', [7, 7]), ('key3', [5, 10]), ('key1', [2, 3])])

Comments

Submit
0 Comments