def get_count(input_str):
return input_str.count("a") + input_str.count("e") + input_str.count("i") + input_str.count("o") + input_str.count("u")
3 Answers
You can simplify this in two ways:
First:
def get_count(input_str, target_str='aeiou'):
return sum(map(input_str.count,target_str))
You can also use collections.Counter
from collections import Counter
def get_count(input_str, target_str='aeiou'):
cnt = Counter(input_str)
return sum([cnt[chr] for chr in target_str])