python - function vowel_count that take a string as inputs count the number of occurrence and prints the occurrence -
i need print number of vowel occurrences in string. able count , print them in 1 line having issue print 'a,e,i,o , u' respectively on occurrence. not allowed use built in function. can 1 please guide or let me know missing. below code.
vowels = 'aeiou' def vowel_count(txt): vowel in vowels: print (txt.count(vowel),end ='') return
it print occurrence not able add in front of it. lets pass le tour de france
should print a,e,i,o , u appear , respectively ,1,3,0,1,1 times
.
please let me know if thing unclear, thanks.
using list comprehension, following can achieved:
vowels = 'aeiou' def vowel_count(txt): counts = map(txt.count, vowels) return ", ".join(vowels) + " appear, respectively, " + ",".join(map(str, counts)) + " times"
Comments
Post a Comment