Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Striped Words by virzen
import re
from functools import reduce
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def isVowel(letter):
return letter.upper() in list(VOWELS)
def isConsonant(letter):
return letter.upper() in list(CONSONANTS)
def isWord(string):
if (len(string) <= 1):
return False
for i in range(1, len(string)):
if (isVowel(string[i])):
if not isConsonant(string[i - 1]):
return False
elif (isConsonant(string[i])):
if not isVowel(string[i - 1]):
return False
else:
return False
return True
def checkio(text):
splitted = re.split('\W+', text)
booleans = map(isWord, splitted)
ints = map(int, booleans)
result = sum(ints)
return result
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert isVowel('A') == True
assert isVowel('C') == False
assert isVowel('o') == True
assert isVowel('f') == False
assert isVowel('') == False
assert isConsonant('A') == False
assert isConsonant('C') == True
assert isConsonant('o') == False
assert isConsonant('f') == True
assert isConsonant('') == False
assert isWord('a') == False
assert isWord('') == False
assert isWord('ff') == False
assert isWord('off') == False
assert isWord('of') == True
assert isWord('ofo') == True
assert checkio(u"My name is ...") == 3, "All words are striped"
assert checkio(u"Hello world") == 0, "No one"
assert checkio(u"A quantity of striped words.") == 1, "Only of"
assert checkio(u"Dog,cat,mouse,bird.Human.") == 3, "Dog, cat and human"
print("All tests passed!")
Jan. 8, 2017