当前位置:网站首页>How to return ordered keys after counter counts the quantity
How to return ordered keys after counter counts the quantity
2022-07-03 02:43:00 【strawberry47】
x = Counter({'a':10, 'b':3, 'c':7})
The return is counterCounter({'a': 10, 'c': 7, 'b': 3})
, I just want to take out the orderly key, How do you do that ?
- If used directly
x.keys()
The return isdict_keys(['a', 'b', 'c'])
, Not the order we want - Use
x.most_common(3)
Return the most frequent 3 individual keys[('a', 10), ('c', 7), ('b', 3)]
, Are tuples and lists - The correct approach :
sorted(x, key=x.get, reverse=True)
Returns the['a', 'c', 'b']
边栏推荐
- [translation] modern application load balancing with centralized control plane
- What is the way out for children from poor families?
- Gbase 8C trigger (II)
- GBase 8c系统表-pg_conversion
- Gbase 8C trigger (III)
- SQL statement
- tensorflow转pytorch笔记;tf.gather_nd(x,y)转pytorch
- 【 tutoriel】 Chrome ferme les cors et les messages de la politique inter - domaines et apporte des cookies à travers les domaines
- Informatics Olympiad one general question bank 1006 a+b questions
- [hcia]no.15 communication between VLANs
猜你喜欢
Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
怎么将yolov5中的PANet层改为BiFPN
"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
Add automatic model generation function to hade
Joking about Domain Driven Design (III) -- Dilemma
easyExcel
[fluent] JSON model conversion (JSON serialization tool | JSON manual serialization | writing dart model classes according to JSON | online automatic conversion of dart classes according to JSON)
[shutter] setup of shutter development environment (supplement the latest information | the latest installation tutorial on August 25, 2021)
Today, it's time to copy the bottom!
随机推荐
JMeter performance test JDBC request (query database to obtain database data) use "suggestions collection"
Gbase 8C system table PG_ am
MATLAB小技巧(24)RBF,GRNN,PNN-神经网络
简单理解svg
Add some hard dishes to the interview: how to improve throughput and timeliness in delayed task scenarios!
GBase 8c系统表pg_cast
Why choose a frame? What frame to choose
The core idea of performance optimization, dry goods sharing
Gbase 8C system table PG_ amop
HW initial preparation
A2L file parsing based on CAN bus (2)
sql server数据库添加 mdf数据库文件,遇到的报错
Restcloud ETL cross database data aggregation operation
Gbase 8C system table PG_ cast
HTB-Devel
Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
Gbase 8C system table PG_ auth_ members
Getting started | jetpack hilt dependency injection framework
[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)
Can netstat still play like this?