Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
readable re solution in Clear category for Striped Words by dronnix
import string
import re
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def checkio(text):
words = re.split('|\\'.join(string.whitespace + string.punctuation), text)
pattern = '(^([{0}][{1}])+[{0}]?$)|(^([{1}][{0}])+[{1}]?$)'.format(VOWELS, CONSONANTS)
counter = 0
for word in words:
counter += re.match(pattern, word.upper()) is not None
return counter
#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"
Sept. 25, 2014