Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Three Words by sedm0784
def checkio(words: str) -> bool:
"""Check if there are three consecutive words in a string"""
# First we split the input into a list
words = words.split()
# Then we create an iterable of each set of three tokens.
# So for the input "a b c d e", triplets is set to:
# [[a, b, c], [b, c, d], [c, d, e]]
triplets = zip(words, words[1:], words[2:])
# Then we check if any of the triplets is "all words"
return any(all(word.isalpha() for word in triplet)
for triplet
in triplets)
June 23, 2021