当前位置:网站首页>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']
边栏推荐
- sql server数据库添加 mdf数据库文件,遇到的报错
- Two dimensional format array format index subscript continuity problem leads to return JSON format problem
- [principles of multithreading and high concurrency: 1_cpu multi-level cache model]
- The solution of "the required function is not supported" in win10 remote desktop connection is to modify the Registry [easy to understand]
- Error when installing MySQL in Linux: starting mysql The server quit without updating PID file ([FAILED]al/mysql/data/l.pid
- easyExcel
- Kubernetes family container housekeeper pod online Q & A?
- 怎么将yolov5中的PANet层改为BiFPN
- Build a private cloud disk cloudrev
- Practice of traffic recording and playback in vivo
猜你喜欢

面试项目技术栈总结

Kubernetes cluster log and efk architecture log scheme
![[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)](/img/6e/67bc187a89fb9125856c78c89f7bfb.gif)
[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)
![[translation] modern application load balancing with centralized control plane](/img/b0/22e9bf098d580b2af67255ddcdc0d5.jpg)
[translation] modern application load balancing with centralized control plane

HTB-Devel

SqlServer行转列PIVOT

Deep learning: multi-layer perceptron and XOR problem (pytoch Implementation)
![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

Restcloud ETL cross database data aggregation operation

Random Shuffle attention
随机推荐
处理数据集,使用LabelEncoder将所有id转换为从0开始
基于can总线的A2L文件解析(2)
A2L file parsing based on CAN bus (2)
Gbase 8C system table PG_ auth_ members
The core idea of performance optimization, dry goods sharing
[hcia]no.15 communication between VLANs
[flutter] example of asynchronous programming code between future and futurebuilder (futurebuilder constructor setting | handling flutter Chinese garbled | complete code example)
Counter统计数量后,如何返回有序的key
错误Invalid bound statement (not found): com.ruoyi.stock.mapper.StockDetailMapper.xxxx解决
Gbase 8C system table PG_ amproc
SQL statement
Concrete CMS vulnerability
Gbase 8C create user / role example 2
Word word word
[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)
Cancer biopsy instruments and kits - market status and future development trends
where 1=1 是什么意思
Pytest (6) -fixture (Firmware)
GBase 8c系统表-pg_am
GBase 8c系统表-pg_amop