20 lines
588 B
Python
20 lines
588 B
Python
|
def contains_word(to_be_checked: str, word: str) -> bool:
|
||
|
word_len: int = len(word)
|
||
|
word_character_number: int = 0
|
||
|
for c in to_be_checked:
|
||
|
if c != word[word_character_number]:
|
||
|
word_character_number = 0
|
||
|
continue
|
||
|
if word_character_number == word_len - 1:
|
||
|
return True
|
||
|
word_character_number += 1
|
||
|
return False
|
||
|
|
||
|
file = open('shakespeare.exp', 'r', encoding='utf8')
|
||
|
result = []
|
||
|
line_number = 0
|
||
|
for line in file:
|
||
|
if contains_word(line, 'Hamlet'):
|
||
|
result.append(line_number)
|
||
|
line_number += 1
|
||
|
print(result)
|