Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Three Words by jcg
def checkio(words, n = 3): # n = number of consecutive words to reach
# counter with reset if any string is not a word
liste = words.split(' ') # split in units to analyze
counter = 0 # counter of consecutive words
for string in liste : # for each string
if string.isalpha() : # if it is a word
counter += 1 # add one
if counter == n : # and if target reached
return True # final
else : # if string not a word
counter = 0 # reset counter
else : # if view all elements
return False # no n consecutive words
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio("Hello World hello") == True, "Hello"
assert checkio("He is 123 man") == False, "123 man"
assert checkio("1 2 3 4") == False, "Digits"
assert checkio("bla bla bla bla") == True, "Bla Bla"
assert checkio("Hi") == False, "Hi"
Feb. 21, 2014
Comments: