Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by petrushev
# migrated from python 2.7
VOWELS = set("AEIOUY")
CONSONANTS = set("BCDFGHJKLMNPQRSTVWXZ")
from string import punctuation
def checkio(text):
for p in punctuation:
text = text.replace(p, ' ')
cnt = 0
for token in text.split(' '):
if len(token) < 2: continue
token = token.upper()
outer = set(token[::2])
inner = set(token[1::2])
if (outer.issubset(VOWELS) and inner.issubset(CONSONANTS)) or \
(inner.issubset(VOWELS) and outer.issubset(CONSONANTS)):
cnt = cnt + 1
return cnt
#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. 14, 2014
Comments: