from random import randint d = {x: randint(60, 100) for x in ‘xyzabcd‘}‘‘‘第一种方法使用zip()方法将字典转化为元组‘‘‘d2 = zip(d.itervalues(), d.iterkeys()) print sorted(d2)‘‘‘第二种方法sorted的key参数‘‘‘d3 = d.items()print sorted(d3, key= lambda x:x[1])
时间: 2024-10-23 06:33:40