Build mini grep
Recursively search text files and return (path, line_number, line) for regex matches.
What you’ll practice
This Level 6 exercise focuses on pathlib + re in the Professional curriculum. Solve the challenge prompt above using clear, idiomatic Python and the relevant language or standard-library tools.
Relevant Python reference: re — Regular expression operations, pathlib — Object-oriented filesystem paths.
Sample Test Cases
mini_grep(root='logs', pattern='ERROR')matching file/line triplesFurther Reading
Reference Solution
Reveal Reference Solution
def mini_grep(root: str, pattern: str): import re from pathlib import Path regex = re.compile(pattern) matches = [] for path in Path(root).rglob('*.txt'): for number, line in enumerate(path.read_text().splitlines(), 1): if regex.search(line): matches.append((str(path), number, line)) return matchesPro Tips & Keyboard Shortcuts
Open VS Code Color Theme Quick Pick to select from 20 dark and light themes.
Open practice settings drawer to toggle line numbers, indenting, font size & hints.
Expand sidebar menu, focus search bar, and highlight search text instantly.
Instantly highlight and focus code editor from anywhere, restoring cursor right where you left off.
Collapse sidebar and close all popups or settings drawers for clean focus view.