【发布时间】:2014-02-10 14:46:50
【问题描述】:
我有一个包含 Unicode 字符串的文件,我正在计算单词并使用 Counter Object 对其进行排序
这是我的代码
import collections
import codecs
from collections import Counter
with io.open('1.txt', 'r', encoding='utf8') as infh:
words =infh.read()
Counter(words)
print Counter(words).most_common(10000)
这是我的 1.txt 文件
വാര്ത്തകള് വാര്ത്തകള് വാര്ത്തകള് വാര്ത്തകള് വാര്ത്തകള് വാര്ത്തകള് വാര്ത്തകള് വാര്ത്തകള്
它为我提供字符数而不是字数 像这样
[(u'\u0d4d', 63), (u'\u0d24', 42), (u'\u200d', 42), (u'\n', 26), (u' ', 21), (u'\u0d30', 21), (u'\u0d33', 21), (u'\u0d35', 21), (u'\u0d15', 21), (u'\u0d3e', 21)]
我的代码有什么问题?
【问题讨论】:
-
words = infh.read().split()
标签: python regex python-2.7 unicode