# 字母计数 生成一个字典,字母做键,出现的次数做值
def count_alphabet(word):
standard = {}
for x in range(ord('a'), ord('z') + 1):
standard[chr(x)] = 0
# 循环传入的单词
for single_alphabet in word:
# 每个字母转成小写
single_alphabet = single_alphabet.lower()
standard[single_alphabet] += 1
return standard
print(count_alphabet("Williamslife"))
效果如下显示: