当前位置:网站首页>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']
边栏推荐
- Gbase 8C system table PG_ amop
- Gbase 8C create user / role example 2
- QT qcombobox add qccheckbox (drop-down list box insert check box, including source code + comments)
- Gbase 8C trigger (III)
- Summary of interview project technology stack
- Oauth2.0 authentication, login and access "/oauth/token", how to get the value of request header authorization (basictoken)???
- Apple releases MacOS 11.6.4 update: mainly security fixes
- cvpr2022去雨去雾
- leetcode540
- Classes and objects - initialization and cleanup of objects - constructor call rules
猜你喜欢

Kubernetes family container housekeeper pod online Q & A?

Basic operation of binary tree (C language version)
![[hcia]no.15 communication between VLANs](/img/59/a467c5920cbccb72040f39f719d701.jpg)
[hcia]no.15 communication between VLANs

random shuffle注意

搭建私有云盘 cloudreve
![[translation] the background project has joined the CNCF incubator](/img/0b/e3d2674b1a1cba3ea398cbcb1a018a.png)
[translation] the background project has joined the CNCF incubator
![[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)](/img/6a/ae44ddb090ce6373f04a550a15f973.jpg)
[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)
![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

easyPOI
![[translation] modern application load balancing with centralized control plane](/img/b0/22e9bf098d580b2af67255ddcdc0d5.jpg)
[translation] modern application load balancing with centralized control plane
随机推荐
Gbase 8C system table PG_ constraint
The left value and the right finger explain better
Unity3d human skin real time rendering real simulated human skin real time rendering "suggestions collection"
Gbase 8C function / stored procedure parameters (II)
The difference between left value and right value in C language
[shutter] bottom navigation bar page frame (bottomnavigationbar bottom navigation bar | pageview sliding page | bottom navigation and sliding page associated operation)
Cvpr2022 remove rain and fog
Gbase 8C system table PG_ attribute
GBase 8c 创建用户/角色 示例二
搭建私有云盘 cloudreve
HW initial preparation
Apple releases MacOS 11.6.4 update: mainly security fixes
Gbase 8C system table PG_ cast
Baidu map - surrounding search
random shuffle注意
【教程】chrome关闭跨域策略cors、samesite,跨域带上cookie
Gbase 8C trigger (I)
Check log4j problems using stain analysis
GBase 8c系统表pg_database
Create + register sub apps_ Define routes, global routes and sub routes