Skip to content
CampusEduX

Word Search in File

Easypython
Learn the Concept: File Handling

Write a program that saves several lines of text to a file, then reads it back line by line and prints only the lines containing a given search word.

What the problem means: search through saved text file content for a specific word, one line at a time — the most common, memory-efficient way to scan a file.

Approach: write the given lines to a file, then loop for line in file: and print any line where the search word is found (using the in operator).

Input: First line: the number of lines n. Next n lines: the text content. Final line: the search word.

Output: Every line (in order) that contains the search word, printed as-is (without the trailing newline).

Related Problems

Input (stdin)

Output

Run your code to see output here...