python计算字母个数

img

img


计算句子中a e i o u单词出现的个数,并在最后一行打印出排除这些字母后剩下的句子

test = input("Enter the text:")
list_vowel = ['a', 'e', 'i', 'o', 'u']
dict1 = {}
str2 = ""
for i in test:
    if i.lower() in list_vowel:
        if i.lower() in dict1.keys():
            dict1[i.lower()] += 1
        else:
            dict1[i.lower()] = 1
    else:
        str2 += i
# 按键排序
list2 = sorted(dict1.items(), key=lambda d:d[0])
# print(list2)
for k, v in list2:
    print(f"'{k}' appears {v} times.", end='\n')
print("Without vowels the text is: ", str2)

text = input('Enter the text:')
aeo_list = {'a': 0, 'e': 0, 'i': 0, 'o': 0, 'u': 0}
rm_text = ''
for temp in text:
    if temp.lower() in aeo_list.keys():
        aeo_list[temp.lower()] += 1
    else:
        rm_text += temp

for key, value in aeo_list.items():
    if value:
        print(f'{key} appears {value} times')
print(f'Without vowels the text is: {rm_text}')

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632