当前位置:网站首页>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 函数/存储过程参数(二)
- Error invalid bound statement (not found): com ruoyi. stock. mapper. StockDetailMapper. XXXX solution
- Add automatic model generation function to hade
- 处理数据集,使用LabelEncoder将所有id转换为从0开始
- Cancer biopsy instruments and kits - market status and future development trends
- 《MATLAB 神经网络43个案例分析》:第43章 神经网络高效编程技巧——基于MATLAB R2012b新版本特性的探讨
- GBase 8c 创建用户/角色 示例二
- 左值右指解释的比较好的
- Compréhension simple de SVG
- Global and Chinese ammonium dimolybdate market in-depth analysis and prospect risk prediction report 2022 Edition
猜你喜欢
What does "where 1=1" mean
搭建私有云盘 cloudreve
《MATLAB 神经网络43个案例分析》:第43章 神经网络高效编程技巧——基于MATLAB R2012b新版本特性的探讨
Build a private cloud disk cloudrev
Pytest (6) -fixture (Firmware)
random shuffle注意
ASP. Net core 6 framework unveiling example demonstration [02]: application development based on routing, MVC and grpc
Practice of traffic recording and playback in vivo
Random Shuffle attention
Can netstat still play like this?
随机推荐
Add MDF database file to SQL Server database, and the error is reported
Gbase 8C system table PG_ amproc
xiaodi-笔记
[hcia]no.15 communication between VLANs
《MATLAB 神经网络43个案例分析》:第43章 神经网络高效编程技巧——基于MATLAB R2012b新版本特性的探讨
Add automatic model generation function to hade
Build a private cloud disk cloudrev
The difference between left value and right value in C language
当lambda没有输入时,是何含义?
[fluent] listview list (map method description of list set | vertical list | horizontal list | code example)
左值右指解释的比较好的
The left value and the right finger explain better
How to change the panet layer in yolov5 to bifpn
GBase 8c系统表-pg_class
Compréhension simple de SVG
Today, it's time to copy the bottom!
GBase 8c系统表-pg_auth_members
GBase 8c系统表-pg_aggregate
Gbase 8C trigger (II)
二维格式数组格式索引下标连续问题导致 返回json 格式问题