Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by Krischtopp
import string
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
REMOVE_PUNCTUATION = str.maketrans(string.punctuation, " " * len(string.punctuation))
def checkio(text):
text = text.upper().translate(REMOVE_PUNCTUATION).split()
return sum(len(word) > 1 and not any(char in string.digits for char in word) and
(all(char in VOWELS for char in word[::2]) and
all(char in CONSONANTS for char in word[1::2]) or
all(char in CONSONANTS for char in word[::2]) and
all(char in VOWELS for char in word[1::2])) for word in text)
# 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"
March 3, 2016
Comments: