Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by Kurush
# migrated from python 2.7
import re
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
DIGITS = "0123456789"
def checkio(text):
words = re.findall(r"[\w]+", text)
count = 0
for word in words:
if len(word) > 1:
word = word.upper()
is_vowel = word[0] in VOWELS
if are_alternating(is_vowel, word):
count += 1
return count
def are_alternating(is_vowel, word):
for char in word:
if char in DIGITS:
return False
if (is_vowel == False) and (char in VOWELS):
return False
if (is_vowel == True) and (char in CONSONANTS):
return False
is_vowel = not is_vowel
return True
#These "asserts" using only for self-checking and not necessary for auto-testing
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"
June 25, 2014