Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using regex solution in Clear category for The End of Other by H0r4c3
import re
def checkio(words_set):
if len(words_set) == 1:
return False
words_list = sorted(list(words_set), key=lambda x : len(x))
for i in range(len(words_list) - 1):
for j in range(i+1, len(words_list)):
regex = words_list[i] + '$'
if re.search(regex, words_list[j]):
return True
return False
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
print("Example:")
print(checkio({"hello", "lo", "he"}))
assert checkio({"hello", "lo", "he"}) == True, "helLO"
assert checkio({"hello", "la", "hellow", "cow"}) == False, "hellow la cow"
assert checkio({"walk", "duckwalk"}) == True, "duck to walk"
assert checkio({"one"}) == False, "Only One"
assert checkio({"helicopter", "li", "he"}) == False, "Only end"
print("Done! Time to check!")
Dec. 3, 2021
Comments: