Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Words Order by Pavellver
def words_order(text: str, words: list) -> bool:
if words[0] in text.split():
if len(words) == 1:
return True
elif -1 != text.split().index(words[0]) < text.split().index(words[1]) != -1 and len(words) == 2:
if words[0] in text.split() and words[1] in text.split():
return True
else:
return False
elif -1 != text.split().index(words[0]) < text.split().index(words[1]) < text.split().index(words[2]) != -1 and len(words) == 3:
return True
else:
return False
else:
return False
print("Example:")
print(words_order("hi world im here", ["world", "here"]))
# These "asserts" are used for self-checking
assert words_order("hi world im here", ["world", "here"]) == True
assert words_order("hi world im here", ["here", "world"]) == False
assert words_order("hi world im here", ["world"]) == True
assert words_order("hi world im here", ["world", "here", "hi"]) == False
assert words_order("hi world im here", ["world", "im", "here"]) == True
assert words_order("hi world im here", ["world", "hi", "here"]) == False
assert words_order("hi world im here", ["world", "world"]) == False
assert words_order("hi world im here", ["country", "world"]) == False
assert words_order("hi world im here", ["wo", "rld"]) == False
assert words_order("", ["world", "here"]) == False
assert words_order("hi world world im here", ["world", "world"]) == False
assert (
words_order("hi world world im here hi world world im here", ["world", "here"])
== True
)
print("The mission is done! Click 'Check Solution' to earn rewards!")
Jan. 29, 2023
Comments: