Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Three Words by alexander.gorelyshev
def checkio(words):
"""Return True if `words` has at least three words without digits in sequence"""
# I'm unaware of a BIF* for searching a list for a slice, so here's a hack:
# (1) We can easily search for a substring in a string
# (2) Integer representation of True is 1
# ---------------------------------------
# Therefore, '111' is a searchable representation of a sequence of 3 desired elements
# Solution:
# (1) Turn a string into a list of strings, splitting by whitespaces
# (2) Turn a list of strings into a list of boolean evaluations
# (3) Turn a list of integer representations of bools into a string
# (4) Test for mission condition being satisfied
return '111' in ''.join(
[str(int(word.isalpha())) for word in words.split()])
# * BIF -- built-in function
#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"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
April 28, 2018