当前位置:网站首页>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']
边栏推荐
- [Hcia]No.15 Vlan间通信
- ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
- GBase 8c系统表-pg_amop
- Principle and application of database
- JS的装箱和拆箱
- Matlab tips (24) RBF, GRNN, PNN neural network
- Gbase 8C system table PG_ am
- Producer consumer model based on thread pool (including blocking queue)
- Gbase 8C system table PG_ attribute
- Monitoring and management of JVM
猜你喜欢
![ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc](/img/cb/145937a27ef08050a370d5a255215a.jpg)
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc

"Analysis of 43 cases of MATLAB neural network": Chapter 43 efficient programming skills of neural network -- Discussion Based on the characteristics of the new version of MATLAB r2012b

Summary of interview project technology stack

xiaodi-笔记

Classes and objects - initialization and cleanup of objects - constructor call rules

UDP receive queue and multiple initialization test

HW initial preparation

Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution

【Flutter】shared_ Preferences local storage (introduction | install the shared_preferences plug-in | use the shared_preferences process)

What does "where 1=1" mean
随机推荐
Simple understanding of SVG
My creation anniversary
HW-初始准备
cvpr2022去雨去雾
MATLAB小技巧(24)RBF,GRNN,PNN-神经网络
[translation] the background project has joined the CNCF incubator
Tongda OA homepage portal workbench
Detailed analysis of micro service component sentinel (hystrix)
Gbase 8C create user / role example 2
Add MDF database file to SQL Server database, and the error is reported
Practice of traffic recording and playback in vivo
Compréhension simple de SVG
JS的装箱和拆箱
Gbase 8C system table PG_ authid
random shuffle注意
Gbase 8C trigger (III)
A2L file parsing based on CAN bus (2)
[shutter] setup of shutter development environment (supplement the latest information | the latest installation tutorial on August 25, 2021)
GBase 8c 创建用户/角色 示例二
Producer consumer model based on thread pool (including blocking queue)