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))

19th Dec 2023, 4:40 AM
FAISAL
3 odpowiedzi
+ 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.
19th Dec 2023, 5:52 PM
Lothar
Lothar - avatar
+ 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
19th Dec 2023, 7:24 AM
卂ㄚㄩ丂卄
卂ㄚㄩ丂卄 - avatar
+ 2
This is faster: x = 'stars in the sky' print(sum((1 for i in x if i in 'AEIOUaeiou'))
22nd Dec 2023, 11:28 PM
Bob_Li
Bob_Li - avatar