The loader returns clean labels and ignores input that shouldn’t become a subdomain candidate. Wordlists are just text files, and text files love arriving with blank lines, comments, and trailing newline characters like confetti.
from pathlib import Pathfrom fixtures.local_targets import course_rootdef load_wordlist(path: Path) ->list[str]: candidates = []with path.open(encoding="utf-8") asfile:for line infile: label = line.strip()ifnot label or label.startswith("#"):continue candidates.append(label)return candidateslabels = load_wordlist(course_root() /"data"/"wordlist.txt")print(labels[:3])
['www', 'mail', 'ftp']
The normal for loop is intentionally readable here: strip the line, skip blanks and comments, and append only useful labels. A list comprehension can work too, but this shape is kinder when you’re still getting comfortable with file handling.