Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Three Words with Regex solution in Creative category for Three Words by tylerl0706
# migrated from python 2.7
__author__ = 'tleonhardt'
# Import Regex helper
import re
# Compiles a regex that difines a digit
_digits = re.compile('\d')
def checkio(words):
# Split the String into an array
words_arr = words.split(" ")
# Loop through the words if there exists 3 words without digits next to each other, return true else return false
for i in range(0, len(words_arr)):
if i+2 < len(words_arr) and not contains_digits(words_arr[i]) and not contains_digits(words_arr[i+1]) \
and not contains_digits(words_arr[i+2]):
return True
return False
def contains_digits(d):
# helper used to check to see if a word has any digits in it
return bool(_digits.search(d))
# 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"
Dec. 15, 2014