例如
>>a = {'a':1, 'b':2, 'c':3}
>>b = a.items()
([('a', 1), ('b', 2), ('c', 3)])
然后对其使用operator.itemgetter(i)函数可以选定键或者值作为排序的依据,i = 0表示按键大小排序
i=1表示按值大小排序
例如
>>a = {'a':1, 'b':2, 'c':3}
>>b = a.items()
([('a', 1), ('b', 2), ('c', 3)])
然后对其使用operator.itemgetter(i)函数可以选定键或者值作为排序的依据,i = 0表示按键大小排序
i=1表示按值大小排序