0
How to solve both case at same time in case nowel finder
# prompt: number of vowels in sentence import re x = "stars in the sky" vowels = re.findall('[AEIOUaeiou]', x) print(len(vowels))
3 Respostas
+ 6
Hm Id ,
when using regex we should prefix the pattern we pass as a *raw string* by using an `r` direct before the beginning of the pattern like:
vowels = re.findall(r'[AEIOUaeiou]', x)
^
in this case it does not matter, but regex frequently uses *backslashes* in the pattern. using raw string ensures that these are treated correctly.
+ 5
If your code is correct then both cases will be passed.
I think instead of providing the value for the variable, use the input function
+ 2
This is faster:
x = 'stars in the sky'
print(sum((1 for i in x if i in 'AEIOUaeiou'))