Skip to content

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

@Luckylisa379

Description

@Luckylisa379

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

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

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,争取年底之前学完。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions