COSC 1210 · CS I (Python) · Iteration and search

Keyword Scanner: Linear Search, One Line at a Time

Watch find_keyword read keywords.txt from top to bottom and test each word against your sentence. It stops at the first match — first in the file, not in the sentence. A sentence without a keyword costs the most: every line has to be checked.
Sentence
try:
Code
keywords.txt
sentence.lower()
Checks needed · every sentence above

Keyboard: → or space step, ← back, p play/pause, e result, r reset.

Built to accompany COSC 1210 (CS I, Python), lectures “Spot a keyword” and “The first reply”. The search runs live on whatever sentence you type, with the ten words of keywords.txt from class. The whole-word test uses a pattern from the lecture on regular expressions: re.search(r"\b" + word + r"\b", sentence.lower()).