Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by grazik
from re import split
VOWELS = list("AEIOUY")
CONSONANTS = list("BCDFGHJKLMNPQRSTVWXZ")
def if_in(a):
return True if a in VOWELS else False
def checkio(text):
text = text.upper()
text = split("[, \-!?:.]+", text)
counter = 0
for i in text:
z = True
if len(i) > 1:
for j in range(len(i) - 1):
if if_in(i[j]) == if_in(i[j+1]) or not i[j].isalpha() or not i[j+1].isalpha():
z = False
break
if z == True and len(i) > 1:
counter += 1
return counter
#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. 24, 2016