I am trying ti convert digit into its spelling alphabet and using dictionary and then pick string
how can i store each user entered number spelling string from dict into list. here is what i tried
num2words = {1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', \
6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine', 10: 'Ten', \
11: 'Eleven', 12: 'Twelve', 13: 'Thirteen', 14: 'Fourteen', \
15: 'Fifteen', 16: 'Sixteen', 17: 'Seventeen', 18: 'Eighteen', \
19: 'Nineteen', 20: 'Twenty', 30: 'Thirty', 40: 'Forty', \
50: 'Fifty', 60: 'Sixty', 70: 'Seventy', 80: 'Eighty', \
90: 'Ninety', 0: 'Zero'}
def n2w(n):
try:
return num2words[n]
except KeyError:
try:
return num2words[n-n%10] + num2words[n%10].lower()
except KeyError:
return 'Number out of range'
n = int(input())
values = list(map(int , input().split()))
x = []
for i in value:
x.append(n2w(i))
Suppose i have vowels ['a' , 'e' , 'i' , 'o' , 'u'] predefined list now i want to count the number of vowels x ? How it can be implemented?