Hello. I have a problem with this code:
def goes_after(word: str, first: str, second: str) -> bool:
if word != "":
for i, current in enumerate(word):
if current == first and word[i+1] == second:
return True
else:
return False
else:
return False
It works for all except the case with the cable. I do not know what the problem with code is?
assert goes_after('world', 'w', 'o') == True ... ok
assert goes_after('world', 'w', 'r') == False ... ok
assert goes_after('world', 'l', 'o') == False ... ok
assert goes_after('list', 'l', 'o') == False ... ok
assert goes_after('', 'l', 'o') == False ... ok
assert goes_after('list', 'l', 'l') == False ... ok
assert goes_after('world', 'd', 'w') == False ... ok
assert goes_after('cable', 'l', 'b') == False ... ok
assert goes_after('cable', 'a', 'b') == True ... Fail
Created at: 2023/10/02 10:50; Updated at: 2023/10/10 10:30
The question is resolved.