Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First, using re library, basic string operations solution in Clear category for Striped Words by Sebastian.M
import re
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def checkio(text):
text = text.upper()
striped = 0
words = re.split(r'[,;.\? ]+',text)
for word in words:
stack = []
if(len(word)>1):
for i in range(len(word)):
if(word[i] in VOWELS):
stack.append('v')
elif(word[i] in CONSONANTS):
stack.append('c')
else:
stack.append('s') #Had to add this due to problems with re.split
if(all(stack[j]!=stack[j+1] for j in range(len(stack)-1)) and not 's' in stack):
striped+=1
return striped
#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. 13, 2016