Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Let's use some built-ins solution in Clear category for Striped Words by belka-fiz
import re
from string import ascii_lowercase
VOWELS = set('aeiouy')
CONSONANTS = set(ascii_lowercase) - VOWELS
def striped(word: str) -> bool:
word = word.lower()
if word[0] in VOWELS: # define the first stripe and set the second one
first, second = VOWELS, CONSONANTS
else:
first, second = CONSONANTS, VOWELS
return all(map(lambda letter: letter in first, word[::2])) and \
all(map(lambda letter: letter in second, word[1::2]))
def checkio(line: str) -> str:
regexp = r"\b[a-zA-Z]{2,}\b" # only latin letters between borders
words = re.findall(regexp, line) # distinct words
return len([word for word in words if striped(word)]) # count striped ones
if __name__ == '__main__':
print("Example:")
print(checkio('My name is ...'))
# These "asserts" are used for self-checking and not for an auto-testing
assert checkio('My name is ...') == 3
assert checkio('Hello world') == 0
assert checkio('A quantity of striped words.') == 1
assert checkio('Dog,cat,mouse,bird.Human.') == 3
print("Coding complete? Click 'Check' to earn cool rewards!")
July 1, 2021