Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by AnnaCho
import re
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def checkio(text):
pattern = ""
for i in text.upper():
if i in VOWELS:
pattern += "0"
elif i in CONSONANTS:
pattern += "1"
elif i.isdigit():
pattern += "X"
else:
pattern += "_"
print(pattern)
count_words = 0
for i in pattern.split("_"):
if len(i) > 1 and not re.search("00|11|X", i):
count_words += 1
return count_words
#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"
assert checkio("Do3g,cat,mouse,bird.Human.") == 2, "Do3g is not a striped word!!!"
Feb. 11, 2015
Comments: