输入一个仅用大小写英文字母组成的字符串,利用字典统计该字符中的各英文字母(不重复)和其对应的出现次数,并输出结果

判断字符串是否是英文字母可用isalpha()
运行结果如下:
请输入一个字符串:Shaai
s 出现 1次
h 出现 1次
a 出现 2次
i 出现 1次


s = input()
temp = {}
for x in s:
    x = x.lower()
    temp[x] = temp.get(x, 0) + 1

for key, value in temp.items():
    print(f'{key}出现{value}次')

s=input()
d={}
for i in s:
    if i.isalpha():
        d[i]=d.get(i,0)+1
for i,j in d.items():
    print("{} 出现 {}次".format(i,j))
words = input("请输入一个字符串:")
counts = {}
for word in words:
    if word.isalpha():
        word =word.lower()
        counts[word] = counts.get(word, 0) + 1
items = list(counts.items())
# items.sort(key=lambda x: x[1], reverse=True)
for i in range(len(counts)):
    word, count = items[i]
    print("{0:s}出现{1:d}次".format(word, count))


img