-
Notifications
You must be signed in to change notification settings - Fork 0
/
Goes Right After.py
35 lines (27 loc) · 1.33 KB
/
Goes Right After.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
https://py.checkio.org/ru/mission/goes-after/
In a given word you need to check if one symbol goes right after another.
Cases you should expect while solving this challenge:
If more than one symbol is in the list you should always count the first one
one of the symbols are not in the given word - your function should return False;
any symbol appears in a word more than once - use only the first one;
two symbols are the same - your function should return False;
the condition is case sensitive, which means 'a' and 'A' are two different symbols.
"""
def goes_after(word: str, first: str, second: str) -> bool:
if first in word:
return True if word.find(first) + 1 == word.find(second) else False
return False
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
print("Coding complete? Click 'Check' to earn cool rewards!")