呼唤远方
首先这是一个由元组组成的列表,可以直接排序>>> s=[('the', 5), ('of', 4), ('a', 3), ('people', 2), ('is', 2), ('when', 2), ('beating', 2) ]>>> s.sort(key=lambda x:(x[1],x[0]))>>> s[('beating', 2), ('is', 2), ('people', 2), ('when', 2), ('a', 3), ('of', 4), ('the', 5)]
暮色呼如
你的意思是数字从大到小,字母按字典顺序如果数字都是正数>>> s=[('the', 5), ('of', 4), ('a', 3), ('people', 2), ('is', 2), ('when', 2), ('beating', 2) ]>>> s.sort(key=lambda x:(-x[1],x[0]))>>> s[('the', 5), ('of', 4), ('a', 3), ('beating', 2), ('is', 2), ('people', 2), ('when', 2)]统计单词个数应该不会有负数吧