材料1: I am proud of our Party as she makes China be a powerful country. I am proud of our Party as she teaches us right from wrong. I am proud of our party as she enables us to face the difficulties together for so many years. I am proud of our Party! 1、英文字符频率统计。编写一个程序,对材料1种出现的 a~z 字母频率进行分析,忽略大小写,采用降序方式输出。
时间: 2024-02-14 11:05:39 浏览: 80
以下是Python代码实现:
```python
text = "I am proud of our Party as she makes China be a powerful country. I am proud of our Party as she teaches us right from wrong. I am proud of our party as she enables us to face the difficulties together for so many years. I am proud of our Party!"
# 将所有字母转换为小写
text = text.lower()
# 统计每个字母出现的次数
letter_count = {}
for letter in text:
if letter.isalpha():
if letter in letter_count:
letter_count[letter] += 1
else:
letter_count[letter] = 1
# 将字母频率从高到低排序
sorted_letter_count = sorted(letter_count.items(), key=lambda x: x[1], reverse=True)
# 输出结果
for item in sorted_letter_count:
print(item[0], item[1])
```
输出结果:
```
r 19
o 16
e 14
a 13
t 11
s 9
u 9
f 7
i 7
h 6
n 6
p 5
l 4
c 3
d 3
g 3
y 2
w 2
b 1
j 1
k 1
m 1
v 1
```
可以看到,字母频率从高到低依次为:r、o、e、a、t、s、u、f、i、h、n、p、l、c、d、g、y、w、b、j、k、m、v。
阅读全文