Varianten - count vowels
unknown
python
8 months ago
364 B
11
Indexable
#classic mit for .. in .. loop
def count_vowels(s):
vowels = "aeiouAEIOU"
count = 0
for char in s:
if char in vowels:
count += 1
return count
#mit regex
def count_vowels(s):
return len(re.findall(r"[aeiouAEIOU]", s))
#mit list comprehesion
def count_vowels(s):
return sum(1 for char in s if char.lower() in "aeiou")Editor is loading...
Leave a Comment