给出英文中26个字母在文本中出现的具体频率
时间: 2024-03-06 22:48:27 浏览: 111
matlab读入英文文本并计算每个字符出现的频率
可以使用Python标准库中的collections模块中的Counter类来实现字母频率的统计。以下是代码示例:
```python
import re
from collections import Counter
# 英文文本
text = "Python is an interpreted high-level programming language for general-purpose programming. Created by Guido van Rossum and first released in 1991."
# 将所有字母转换为小写并去除非字母字符
letters = re.findall(r'[a-zA-Z]', text.lower())
# 计算字母频率
letter_counts = Counter(letters)
# 输出字母频率的统计表
for letter in 'abcdefghijklmnopqrstuvwxyz':
count = letter_counts[letter]
freq = count / len(letters)
print(f'{letter}: {count}, {freq:.2%}')
```
运行代码后,会输出英文文本中26个字母出现的具体频率统计表。
阅读全文