Find-and-replace across many lines
P42.from-paper-to-notebook.03 · Audience: Guest, Language professional, IT/ML learner · Prerequisites: Build a vocabulary table
Where next?
Later in From Paper to Notebook
P42.from-paper-to-notebook.03 · Audience: Guest, Language professional, IT/ML learner · Prerequisites: Build a vocabulary table
Later in From Paper to Notebook
A term was renamed, a client became a customer, a spelling was standardised —
and now it must change everywhere. In a document you would scroll through and fix
each line by hand, hoping to miss none. The notebook applies the one rule to the
whole list at once: a loop over the lines and .replace on each.
line.replace(OLD, NEW) returns a new string with every OLD swapped for NEW. The original line is left exactly as it was — replace hands you a fresh copy rather than editing in place, so nothing is lost.Why it matters — Knowing that replace returns a new string — and never touches the original — is what makes it safe to run across a whole document.
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Your turn: loop over the lines and build a new list with the old word replaced by the new one on every line. Press Run.
Loading exercise…
Loading your notes...