Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
str.translate solution in Clear category for Striped Words by Splitter
VOWELS = "AEIOUY"
CONSONANTS = "BCDFGHJKLMNPQRSTVWXZ"
def is_striped(word):
char_types = word.translate(str.maketrans('AEIOUY', '000000'))
char_types = char_types.translate(str.maketrans('BCDFGHJKLMNPQRSTVWXZ',
'11111111111111111111'))
# another way char_types = ''.join([str(+(ch in VOWELS)) for ch in word])
return True if '00' not in char_types and '11' not in char_types else False
def checkio(text):
text = text.upper().translate(str.maketrans('.,:;-?!', ' '))
check = lambda word: len(word) > 1 and word.isalpha() and is_striped(word)
return len(list(filter(check, text.split(' '))))
#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"
July 25, 2019
Comments: