当前位置:网站首页>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']
边栏推荐
- Gbase 8C system table PG_ amproc
- The Linux server needs to install the agent software EPS (agent) database
- 簡單理解svg
- Oauth2.0 authentication, login and access "/oauth/token", how to get the value of request header authorization (basictoken)???
- 【 tutoriel】 Chrome ferme les cors et les messages de la politique inter - domaines et apporte des cookies à travers les domaines
- Basic operation of binary tree (C language version)
- GBase 8c系统表-pg_amproc
- 【ROS进阶篇】第六讲 ROS中的录制与回放(rosbag)
- GBase 8c系统表-pg_auth_members
- 面试项目技术栈总结
猜你喜欢
![[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)](/img/e5/c01f760b07b495f5b048ea367e0c21.gif)
[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)

easyExcel

HW initial preparation

Baidu map - surrounding search

Restcloud ETL cross database data aggregation operation

The Linux server needs to install the agent software EPS (agent) database

HW-初始准备

Create + register sub apps_ Define routes, global routes and sub routes

定了,就选它

Kubernetes family container housekeeper pod online Q & A?
随机推荐
搭建私有云盘 cloudreve
Two dimensional format array format index subscript continuity problem leads to return JSON format problem
Check log4j problems using stain analysis
Mathematical statistics -- Sampling and sampling distribution
Principle and application of database
5. File operation
Baidu map - surrounding search
Gbase 8C system table PG_ collation
【翻译】后台项目加入了CNCF孵化器
GBase 8c 函数/存储过程参数(一)
Pytest (6) -fixture (Firmware)
Awk from entry to burial (1) awk first meeting
GBase 8c系统表-pg_class
Gbase 8C system table PG_ amproc
【翻译】Flux安全。通过模糊处理获得更多信心
UDP receive queue and multiple initialization test
The data in servlet is transferred to JSP page, and the problem cannot be displayed using El expression ${}
GBase 8c系统表-pg_authid
Gbase 8C system table PG_ authid
Return a tree structure data