我希望能够找到一种方法来计算文本中不同字母的频率,其中一些字母使用了变音符号。例如,文本中既使用了“å”,又使用了“ą̊”(U+00E5 U+0328),需要分别计算其频率。
我该怎么做呢?
我尝试使用Counter集合,使用utf8格式打开文件,使用
我该怎么做呢?
我尝试使用Counter集合,使用utf8格式打开文件,使用
text.split()
和list(text)
拆分文本字符串,但Python仍将“å”和“ą̊”视为相同的字母!
if unicodedata.category("character")[0] == "M":
这行代码时,应注意不要将character
放在引号内,因为它是一个变量。 - olooneyunicodedata.normalize
和unicodedata.category
,所以这里提供链接,如果其他人需要的话: https://docs.python.org/2/library/unicodedata.html#unicodedata.normalize https://docs.python.org/2/library/unicodedata.html#unicodedata.category http://www.fileformat.info/info/unicode/category/index.htm非常感谢您的帮助! - user11448