Text Processing Like a Pro
Lesson 1 of 5 · View course roadmap
Learn the idea
Most automation is text manipulation. Your core toolkit:
s.split(",")— string → list;", ".join(items)— list → strings.startswith(x)/s.endswith(x)— prefix/suffix testss.find(x)— index of a substring (-1 if absent);x in s— simple tests.splitlines()— split text into lines- Chaining:
line.strip().lower().split(";")
The split → transform → join pipeline is the bread and butter of every data-cleaning script ever written.
Where you'll use this
Data cleaning is famously 80% of data work, and it's split/strip/join all the way down: normalising user input, parsing log lines, generating URL slugs (this site's lesson URLs were made exactly like your challenge).
Common mistakes
- Forgetting strip() on user input or file lines — invisible whitespace and newlines break comparisons:
"cat\n" != "cat". - join's calling direction: it's
", ".join(items)— separator first — and every item must already be a string (map(str, items) if not). - replace() returns a new string; the original is untouched unless you reassign.
Pro tip
Chain transformations left-to-right for readable pipelines: line.strip().lower().replace(",", "") — each step returns a string, so they compose forever.
Try it yourself
The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.
Output appears here…
Pass the challenge +30 XP
Take the starter sentence, and print it as a slug: lowercase, words joined by hyphens. Expected: learn-python-the-fast-way
learn-python-the-fast-way
"-".join(title.lower().split())
title = "Learn Python The Fast Way" slug = "-".join(title.lower().split()) print(slug)
Run your code to check it…
Check your understanding
Your notes (saved on this device)
Tip: use ← and → to move between lessons, ⌘K to search everything.