Loading

关于Python123中的排序问题

关于Python123中的排序问题

统计方法

1、collections.Counter

2、dic={k:ls.count(k) for k in set(ls)}

3、dic[i]=dic.get(i,0)+1

排序方法:

1、sorted(dic.items(),key=lambda x:x[1])[:5]

2、heapq.nsmallest(5,dic.items(),key=lambda x:x[1])

posted @ 2021-08-16 15:02  橘崽崽啊  阅读(88)  评论(0编辑  收藏  举报