Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Regular expression then slices solution in Speedy category for Striped Words by richshelswell
import re
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def checkio(text):
words = re.split('\W+',text.upper())
chars = list([l for l in w] for w in words if w.isalpha() and len(w) > 1)
s = sum([(all([l in CONSONANTS for l in w[0::2]])
and all([l in VOWELS for l in w[1::2]]))
or (all([l in VOWELS for l in w[0::2]])
and all([l in CONSONANTS for l in w[1::2]])) for w in chars])
return s
#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"
Feb. 13, 2016