Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Verbose but clear solution solution in Clear category for Striped Words by weatherpattern
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
NUMBERS = "0123456789"
def checkio(text):
# string -> integer
count = 0
new_text = ""
text = text.upper()
#print ("text: ", text)
for character in text:
if character in VOWELS or character in CONSONANTS or character in NUMBERS:
new_text += character
else:
new_text += " "
new_text = new_text.split()
for word in new_text:
if len(word) > 1:
for index in range(len(word)-1):
if word[index] in NUMBERS:
break
elif word[index] in VOWELS and word[index+1] in VOWELS:
break
elif word[index] in CONSONANTS and word[index+1] in CONSONANTS:
break
else: count += 1
#print ("new_text: ", new_text, "count: ", count)
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. 9, 2016