1.range
In [3]: for i in range(4,0,-1): ...: print(i) ...: 4 3 2 1 2.sorted,lambda
dic = {('a', 10), ('b', 7), ('c', 7), ('d', 5), ('f', 5), ('e', 4), ('g', 3), ('h', 2), ('i', 2), ('j', 2)} sorted(dic, key=lambda x:x[0],reverse=True)
结果: [('j', 2), ('i', 2), ('h', 2), ('g', 3), ('f', 5), ('e', 4), ('d', 5), ('c', 7), ('b', 7), ('a', 10)]
sorted(dic, key=lambda x:x[1],reverse=True)
[('a', 10), ('b', 7), ('c', 7), |
|