Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Generate sort set solution in Clear category for Words Order by Striga
def words_order(text: str, words: list) -> bool:
word_set = {w for w in text.split() if w in words}
return list(sorted(word_set, key = text.index)) == words
if __name__ == '__main__':
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
Oct. 3, 2020
Comments: