Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Explained solution in Clear category for Goes Right After by Selindian
def goes_after(word: str, first: str, second: str) -> bool:
# your code here
i1 = word.find(first) # index of 1st word (-1 if not found)
i2 = word.find(second) # index of 2nd word (-1 if not found)
return i1 + 1 == i2 and i1 != -1 and i2 != -1 # True when i2 directly after i1 (i1+1==i2) and both found (not -1)
if __name__ == "__main__":
print("Example:")
print(goes_after("world", "w", "o"))
# These "asserts" are used for self-checking and not for an auto-testing
assert goes_after("world", "w", "o") == True
assert goes_after("world", "w", "r") == False
assert goes_after("world", "l", "o") == False
assert goes_after("panorama", "a", "n") == True
assert goes_after("list", "l", "o") == False
assert goes_after("", "l", "o") == False
assert goes_after("list", "l", "l") == False
assert goes_after("world", "d", "w") == False
assert goes_after("transport", "r", "t") == False
print("Coding complete? Click 'Check' to earn cool rewards!")
Feb. 28, 2022
Comments: