Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Several lines with per-line comments. I like the task:))) solution in Clear category for Striped Words by tkachuk.constantine
from string import punctuation
def checkio(line: str) -> str:
vowels = 'AEIOUY'
# To avoid repeatition
func1 = lambda x: x in vowels
# Verify word complance with rules of the game
def verify(piece: str) -> bool:
flag = func1(piece[0])
for i in piece[1:]:
if func1(i) != flag: flag = func1(i)
else: return False
return True
# Principle: avoid side effects. Just to prevent modification of the incoming variable
new_line = line
# Punctuation removal
for i in punctuation: new_line = new_line.replace(i, ' ')
# Spliting into list with capitalization
words = [w.strip() for w in new_line.upper().split()]
#remove mixed literals - number and digits
words = [w for w in words if w.isalpha() and len(w) > 1]
return sum(map(verify, words))
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!")
June 29, 2021
Comments: