我需要在下面的语句中打印a's,b,c's等的数目,并将它级联下来,并在它旁边的语句中显示它的次数。
“你可以拥有没有信息的数据,但没有数据你就不能拥有信息。”
我到目前为止还能得到一些帮助吗?
今天是我学习蟒蛇的第三天,所以别紧张。
from collections import defaultdict
text = 'You can have data without information, but you cannot have information without data.'
lowerCaseText = text.lower()
print(lowerCaseText)
chars = defaultdict(int)
for char in text:
chars[char] += 1
print(chars)它需要看起来像这样
a : 10
b : 1
c : 2
d : 2
e : 2
f : 2
h : 4
i : 6
m : 2
n : 7
o : 9
r : 2
t : 10
u : 5
v : 2
w : 2
y : 2https://stackoverflow.com/questions/74042928
复制相似问题