Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by iwo.malyszka
import re
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def checkio(text):
my_regex = '[^\dA-Z]+'
count = 0
is_striped = False
my_text = text.upper()
words = re.split(my_regex, my_text)
for word in words:
if len(word) <= 1 or not word.isalpha():
continue
is_striped = True
for ch in range(0,(len(word) - 1)):
if (VOWELS.find(word[ch]) != -1 ) and (VOWELS.find(word[ch+1]) != -1):
is_striped = False
break
if (CONSONANTS.find(word[ch]) != -1) and (CONSONANTS.find(word[ch+1]) != -1):
is_striped = False
break
if is_striped:
count += 1
return count
#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"
Oct. 23, 2016