Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
v2: using slicing, sets, generator and translation of punctuation =) solution in Clear category for Striped Words by Phil15
from string import ascii_uppercase, punctuation
VOW = set('AEIOUY')
CONS = set(ascii_uppercase) - VOW
def checkio(text):
text = text.translate(str.maketrans(punctuation, ' '*32))
words = (word.upper() for word in text.split()
if len(word) > 1 and word.isalpha())
count_words = 0
for word in words:
even, odd = set(word[::2]), set(word[1::2])
if (even <= VOW and odd <= CONS) or (odd <= VOW and even <= CONS):
count_words += 1
return count_words
if __name__ == '__main__':
assert checkio("My name is ...") == 3, "All words are striped"
assert checkio("Hello world") == 0, "No one"
assert checkio("A quantity of striped words.") == 1, "Only of"
assert checkio("Dog,cat,mouse,bird.Human.") == 3, "Dog, cat and human"
Aug. 16, 2018