从网上下载一篇文章,统计每个字出现的次数,不计标点符号,按照次数排序

content=''' 软件测试工程师(Software Testing Engineer)指理解产品的功能要求,并对其进行测试,检查软件有没有缺陷(Bug),测试软件是否具有稳定性(Robustness)、安全性、易操作性等性能,写出相应的测试规范和测试用例的专门工作人员。 简而言之,软件测试工程师在一家软件企业中担当的是“质量管理”角色,及时发现软件问题并及时督促更正,确保产品的正常运作。按其级别和职位的不同,分为三类。 '''
punctuations=['(',',','。','“','、',' ',')','”','\n']
for punctuation in punctuations:
    content=content.replace(punctuation,'')  #替换标点符号
print(content)
#用字典存储:字符:次数
result={ }
for word in content:
    if word in result:
        result[word]=result[word]+1 #该字符第N次在字典里
    else:
        result[word]=1  #该字符第一次在字典里
print(result)
#按照次数从大到小排序
fin_result=list(zip(result.values(),result.keys()))
fin_result.sort(reverse=True,key=lambda x:x[0])
print(fin_result)

本文地址:https://blog.csdn.net/weixin_47226008/article/details/110882617