python实现统计单词出现的位置和数量
2017-10-30 18:23
2246 查看
import sys import re WORD_RE = re.compile(r'\w+') index = {} with open(sys.argv[1], encoding='utf-8') as fp: for line_no, line in enumerate(fp, 1): for match in WORD_RE.finditer(line): word = match.group() column_no = match.start()+1 location = (line_no, column_no) index.setdefault(word, []).append(location) for word in sorted(index, key=str.upper): print(word, index[word])
相关文章推荐
- 一个简单的程序,统计文本文档中的单词和汉字数,逆序排列(出现频率高的排在最前面)。python实现。
- python3 实现统计单词表中每个字母的出现频率
- python实现统计文本中单词出现的频率
- Python实现统计单词出现的个数
- 每天一个小程序之python实现统计英文单词出现个数
- Python实现统计文本当中单词的数量,
- 统计英文文章中出现的单词数量(基于字节实现)
- Python实现统计单词出现的个数
- 如何用Python实现任一个英文的纯文本文件,统计其中的单词出现的个数?
- 任意一个英文的纯文本文件,统计其中的单词出现的个数(shell python 两种语言实现)
- Python实现统计英文单词个数及字符串分割代码
- python统计文本文件内单词数量的方法
- python实现文本中单词个数统计
- 第0004道练习题_Python统计文本里单词出现次数
- 遍历Map方法一(通过HashMap类实现统计单词出现次数)
- 金山2014秋招笔试题——统计单词在一篇文章中出现的次数和位置
- Python 练习册 6-统计文本文件中的出现最多的单词
- 遍历Map方法一(通过HashMap类实现统计单词出现次数)
- 【Python】利用setdefault函数实现dict的转置(key与value对互换),统计value出现的次数
- List列表实现统计文档中单词出现的次数