Skip to content

Day6 怎样将文档中所有的特殊字符都去除呢? #5887

@DainDain

Description

@DainDain
  1. text = input('请输入你要处理的文档:')
  2. def stats_text_en(text):
  3.     text=text.replace('!',' ') #面对待处理的文档,没办法把可能出现的特殊字符都遍历一边然后替换,如果使用.isalpha()的话会把空格都删掉,该怎么办呢?
  4.     text=text.lower()
  5.     text=text.split()
  6.     dict1={}
  7.     for i in text:
  8.         j=text.count(i)
  9.         dict2={i:j}
  10.         dict1.update(dict2)
  11.         dict2=sorted(dict1.items(),key=lambda x:x[1],reverse=True)
  12.     print(dict2)
  13. stats_text_en(text)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions