用python 列出文章中使用最频繁的诗歌单词,并给出它们的出现次数
来源:学生作业帮 编辑:作业帮 分类:英语作业 时间:2024/05/21 10:33:08
用python 列出文章中使用最频繁的诗歌单词,并给出它们的出现次数
这个用python2.7测试通过.import urllib2
import re
from collections import Counter
def get_data(url):
resp = urllib2.urlopen(url).read()
return resp
def analyse(text, n=1):
''' show the n most common words in text '''
res = Counter(re.split(r'\W+', text, flags=re.M)).most_common(n)
print('words\ttimes')
print('\n'.join([k+'\t'+str(v) for k,v in res]))
def main():
data = get_data('http://www.umich.edu/~umfandsf/other/ebooks/alice30.txt')
analyse(data, 1)
main()结果是:wordstimes
the1525可以自己调整给analyse()的参数n来控制打印多少频繁出现的单词.
import re
from collections import Counter
def get_data(url):
resp = urllib2.urlopen(url).read()
return resp
def analyse(text, n=1):
''' show the n most common words in text '''
res = Counter(re.split(r'\W+', text, flags=re.M)).most_common(n)
print('words\ttimes')
print('\n'.join([k+'\t'+str(v) for k,v in res]))
def main():
data = get_data('http://www.umich.edu/~umfandsf/other/ebooks/alice30.txt')
analyse(data, 1)
main()结果是:wordstimes
the1525可以自己调整给analyse()的参数n来控制打印多少频繁出现的单词.
用python 列出文章中使用最频繁的诗歌单词,并给出它们的出现次数
python 统计单词平均长度,统计a出现的次数
编写一个程序.功能是读入一篇英文文章,统计该文章中每个单词的出现次数,并输出出现次数最多的前5个单词及其出现次数.
英文歌中最频繁出现的词
做一个C#程序;列出文本中的每个单词和每个单词出现的次数.以及每个单词在句子中出现的次数.
JAVA统计一篇文章中所有单词出现的次数,并按字典序将单词及频数输出到文件中
用PHP 计算出文章中各个字母出现的次数
从文件中读入一段英语文章,统计文章中单词的数量,求出现次数最多和最少的单词和数量.用C怎么实现?
java编程 写一段程序统计一段字符串中每一个单词的出现次数 并按照次数的倒序输出
有没有能统计一篇英文文章中所有单词出现次数的软件
如何在一篇文章中查找某个单词出现的次数
求教一C程序题 计算英文文章中某一单词出现的次数