求助:python 二级字典如何快速排序

2022-08-05 社会 57阅读
def sbv0(adict,reverse=False):
return sorted(adict.iteritems(), key=lambda (k,v): (v,k), reverse=reverse)

def sbv1(d,reverse=False):
L = [(k,v) for (k,v) in d.iteritems()]
return sorted(L, key=lambda x: x[1] , reverse=reverse)

def sbv2(d,reverse=False):
L = ((k,v) for (k,v) in d.iteritems())
return sorted(L, key=lambda x: x[1] , reverse=reverse)

def sbv3(d,reverse=False):
return sorted(d.iteritems(), key=lambda x: x[1] , reverse=reverse)

def sbv4(d,reverse=False):
def sk(x):
return x[1]
return sorted(d.iteritems(), key=sk , reverse=reverse)

def sk(x):
return x[1]

def sbv5(d,reverse=False):
return sorted(d.iteritems(), key=sk , reverse=reverse)

from operator import itemgetter
def sbv6(d,reverse=False):
return sorted(d.iteritems(), key=itemgetter(1), reverse=True)

D = dict(zip(range(100),range(100)))

from profile import run

for ii in xrange(10000):
sbv6(D, reverse=True)
#run(for ii in xrange(10000): sbv0(D, reverse=True))
#run(for ii in xrange(10000): sbv1(D, reverse=True))
#run(for ii in xrange(10000): sbv2(D, reverse=True))
#run(for ii in xrange(10000): sbv3(D, reverse=True))
#run(for ii in xrange(10000): sbv4(D, reverse=True))
#run(for ii in xrange(10000): sbv5(D, reverse=True))
#run(for ii in xrange(10000): sbv6(D, reverse=True))
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com