博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
中英文词频
阅读量:5768 次
发布时间:2019-06-18

本文共 2526 字,大约阅读时间需要 8 分钟。

str2='''I will run, I will climb, I will soarI'm undefeatedJumpiing out of my skin, pull the chordYeah I believe itThe past, is everything we weredon't make us who we areSo I'll dream, until I make it real,and all I see is starsIts not until you fall that you flyWhen your dreams come alive you're unstoppableTake a shot, chase the sun, find the beautifulWe will glow in the dark turning dust to goldAnd we'll dream it possiblepossibleAnd we'll dream it possibleI will chase, I will reach, I will flyUntil I'm breaking, until I'm breakingOut of my cage, like a bird in the nightI know I'm changing, I know I'm changingIn, into something big, better than beforeAnd if it takes, takes a thousand livesThen it's worth fighting forIts not until you fall that you flyWhen your dreams come alive you're unstoppableTake a shot, chase the sun, find the beautifulWe will glow in the dark turning dust to goldAnd we'll dream it possibleit possibleFrom the bottom to the topWe're sparking wild fire'sNever quit and never stopThe rest of our livesFrom the bottom to the topWe're sparking wild fire'sNever quit and never stopIts not until you fall that you flyWhen your dreams come alive you're unstoppableTake a shot, chase the sun, find the beautifulWe will glow in the dark turning dust to goldAnd we'll dream it possiblepossibleAnd we'll dream it possible'''.lower()#aa = '''."?!'''#for word in aa:#   str2 =str2.replace('word','')str2 =str2.replace('\n',' ')str2 =str2.replace(',',' ')print(str2)#去除特殊符号 str2 = str2.strip()#去掉首尾空格str2 = str2.split()#通过指定分隔符对字符串进行切片print(str2) print('统计每个单词出现的次数为:')for word in str2:   print(word,str2.count(word)) strSet=set(str2)newSet={'a','will','it','out','of','my','the','i','in','to','when','and'}strSet1=strSet-newSet#去除介词和其他print(strSet1)  strdict={}          #单词计数字典for word in strSet1:    strdict[word] = str2.count(word)print(len(strdict),strdict) strList = list(strdict.items())def takesecond(elem):#定义函数        return elem[1]#strList.sort(key=lambda x:x[1],reverse=True)#匿名函数strList.sort(key=takesecond,reverse=True)#按照数值大小进行排序print(strList)  for i in range(20):    print (strList[i])#前二十

  

import jiebaf=open('《活着》.txt','r',encoding='utf-8')life=f.read()f.close()lifelist=list(jieba.cut(life))lifedict={}for word in lifelist:    if len(word)==1:        continue    else:        lifedict[word]=lifedict.get(word,0)+1 wordlist=list(lifedict.items())wordlist.sort(key=lambda x:x[1],reverse=True) for a in range(15):    print(wordlist[a])

  

转载于:https://www.cnblogs.com/PMAM/p/9824374.html

你可能感兴趣的文章
[zz] fstab mtab
查看>>
2011-04-18 python 文件copy 之道 大全 (转)
查看>>
用javascript获取地址栏参数
查看>>
解析xml
查看>>
一起谈.NET技术,你应该知道的15个Silverlight诀窍
查看>>
SQL注入漏洞全接触--进阶篇
查看>>
电商应用脚本开发遇到问题和处理
查看>>
商教助手!解析夏普液晶高清宽屏投影机系列
查看>>
中国平安增持华夏幸福5.69%股权 看好长期战略协同
查看>>
云南去年有望实现151万贫困人口净脱贫
查看>>
Java架构师面试题系列整理(大全)
查看>>
延伸产业链 中国产粮大省向“精深”问发展
查看>>
消费贷用户70%月收入低于5000元 80、90后是主要人群
查看>>
2018年内蒙古外贸首次突破1000亿元
查看>>
为什么主流APP的推荐总能符合你口味?推荐系统了解一下
查看>>
完整的大数据知识体系,大数据学习路线图
查看>>
硬核NeruIPS 2018最佳论文,一个神经了的常微分方程
查看>>
大数据平台技术栈
查看>>
CTOR有助于BCH石墨烯技术更上一层楼
查看>>
被遗忘的CSS
查看>>