当前位置:网站首页>Counter统计数量后,如何返回有序的key
Counter统计数量后,如何返回有序的key
2022-07-03 02:39:00 【strawberry47】
x = Counter({'a':10, 'b':3, 'c':7})
返回的是counterCounter({'a': 10, 'c': 7, 'b': 3})
,我只想取出有序的key,该怎么做呢?
- 如果直接使用
x.keys()
返回的是dict_keys(['a', 'b', 'c'])
,并非我们想要的顺序 - 使用
x.most_common(3)
返回频率最高的3个keys[('a', 10), ('c', 7), ('b', 3)]
,是元组和列表形式 - 正确做法:
sorted(x, key=x.get, reverse=True)
会返回['a', 'c', 'b']
边栏推荐
猜你喜欢
Pytorch convolution network regularization dropblock
Baidu map - surrounding search
Choose it when you decide
[Hcia]No.15 Vlan间通信
4. Classes and objects
sql server数据库添加 mdf数据库文件,遇到的报错
xiaodi-笔记
Principle and application of database
How to change the panet layer in yolov5 to bifpn
Practice of traffic recording and playback in vivo
随机推荐
Check log4j problems using stain analysis
where 1=1 是什么意思
sql server 查询指定表的表结构
Two dimensional format array format index subscript continuity problem leads to return JSON format problem
Compréhension simple de SVG
HW-初始准备
HTB-Devel
[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)
GBase 8c系统表pg_database
Memory pool (understand the process of new developing space from the perspective of kernel)
MATLAB小技巧(24)RBF,GRNN,PNN-神经网络
【翻译】具有集中控制平面的现代应用负载平衡
Tongda OA V12 process center
Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
GBase 8c系统表-pg_class
Gbase 8C system table PG_ database
Packing and unpacking of JS
GBase 8c系统表-pg_conversion
Gbase 8C trigger (I)
How to change the panet layer in yolov5 to bifpn