-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstriped-words.py
35 lines (28 loc) · 1.15 KB
/
striped-words.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from string import ascii_letters, punctuation
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def checkio(text):
ans, text = 0, text.lower()
vowels, consonants = VOWELS.lower(), CONSONANTS.lower()
for p in punctuation:
text = text.replace(p, " ")
for word in text.split():
if len(word) > 1:
odd = word[::2]
even = word[1::2]
if set(odd).issubset(set(ascii_letters)) and \
set(even).issubset(set(ascii_letters)):
if (set(odd).issubset(set(vowels)) and
set(even).issubset(set(consonants))) or \
(set(even).issubset(set(vowels)) and
set(odd).issubset(set(consonants))):
# odd-vow even-cons OR odd-cons even-vow
ans = ans + 1
return ans
def test_function():
assert checkio(u"My name is ...") == 3, "All words are striped"
assert checkio(u"Hello world") == 0, "No one"
assert checkio(u"A quantity of striped words.") == 1, "Only of"
assert checkio(u"Dog,cat,mouse,bird.Human.") == 3, "Dog, cat and human"
if __name__ == '__main__':
test_function()