当前位置:网站首页>Word frequency statistics & sorting
Word frequency statistics & sorting
2022-07-02 13:54:00 【Chloris_】
# Word frequency statistics
sent = "python is my favoriate language,you're so cute ,someone like you ~~,do what shhhh"
# newest
output = {k:sent.count(k) for k in set(sent)}# Get word frequency statistics quickly
print(output)
output = {k:sent.count(k) for k in set(sent.split(" "))}# Get word frequency statistics quickly
print(output)
chset = "abcdefghijklmnopqrstuvwxyz-' "
sent = sent.lower()# Lowercase letters
for c in sent:
if c not in chset:
sent = sent.replace(c," ")
wd_lst = sent.split(" ")# Split by spaces
wd_lst
dt = {}
for k in wd_lst:
if k not in dt.keys():
dt[k] = 0
dt[k]+=1
wd_s = set(wd_lst)
dt1 = {}
for k in wd_s:
dt1[k] = wd_lst.count(k)
According to the value It's worth it key Sort :
a1 = sorted(word_freqs_c.items(),key = lambda x:x[1],reverse = True)
边栏推荐
- [Unity]使用GB2312,打包后程序不正常解决方案
- I did it with two lines of code. As a result, my sister had a more ingenious way
- BeanUtils -- shallow copy -- example / principle
- Winter vacation daily question - lucky numbers in the matrix
- Selenium, element operation and browser operation methods
- 石子合并板子【区间DP】(普通石子合并 & 环形石子合并)
- Error: eacces: permission denied, access to "/usr/lib/node_modules"
- 题解《子数整数》、《欢乐地跳》、《开灯》
- Node. JS accessing PostgreSQL database through ODBC
- How to use SAP's metadata framework (MDF) to build custom business rules?
猜你喜欢
Selenium, element operation and browser operation methods
[技术发展-22]:网络与通信技术的应用与发展快速概览-2- 通信技术
浏览器驱动的下载
QT new project_ MyNotepad++
Common options of tcpdump command: Three
Chinese name extraction (toy code - accurate head is too small, right to play)
uniapp小程序 subPackages分包配置
为什么switch 的default后面要跟break?
[cloud native database] what to do when encountering slow SQL (Part 1)?
【文档树、设置】字体变小
随机推荐
693. 行程排序(map + 拓扑)
Detailed collection of common MySQL commands
如何设置Qt手工布局
Winter vacation daily question - lucky numbers in the matrix
题解:《你的飞碟在这儿》、《哥德巴赫猜想》
P1908 逆序对
量子三体问题: Landau Fall
Code implementation MNLM
Slashgear shares 2021 life changing technology products, which are somewhat unexpected
[cloud native database] what to do when encountering slow SQL (Part 1)?
Let juicefs help you with "remote backup"
你的 Sleep 服务会梦到服务网格外的 bookinfo 吗
Redis database persistence
selenium的特点
Solve "sub number integer", "jump happily", "turn on the light"
Browser driven Download
瀏覽器驅動的下載
Origin plots thermogravimetric TG and differential thermogravimetric DTG curves
Chinese name extraction (toy code - accurate head is too small, right to play)
2022 Heilongjiang provincial examination on the writing skills of Application Essays