Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

day05 如何按照从大到小排序呢? #6046

Open
Luckylisa379 opened this issue Oct 9, 2019 · 0 comments
Open

day05 如何按照从大到小排序呢? #6046

Luckylisa379 opened this issue Oct 9, 2019 · 0 comments

Comments

@Luckylisa379
Copy link
Contributor

下面是我自己写的代码,可以计算出每个单词的个数,但不知道怎么写按照从大到小排序了。
我看了其他人的代码基本上都是一步步出来的,看着代码能够理解,不过我希望能够使用下列字典推导式的代码一步写出来。请问在这个方法基础上怎么加入排序呢?

去掉符号、空格及将字母全部改成小写

text_a=text.replace(',','').replace('.','').replace('--','').replace('!','')
text_b=(text_a.lower()).split()
print(text_b)

在前一步基础上,使用字典统计各英文单词的个数

text_dict = {i:text_b.count(i) for i in text_b}
print(text_dict)

*停了好多个月重新开始学真是不容易啊,相当于从0再开始终于又有点回到入门的感觉了,这次哪怕进度慢一点也要坚持学到最后。给自己立个Flag,争取年底之前学完。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant