Free lab Real Python 3. Zero installs. Your code stays in this browser. Open the playground

Text Processing Like a Pro

14 min 30 XP
Study loop Read Predict Run Tweak Prove Review
Lesson 1 of 5 · View course roadmap
Step 1

Learn the idea

Most automation is text manipulation. Your core toolkit:

  • s.split(",") — string → list; ", ".join(items) — list → string
  • s.startswith(x) / s.endswith(x) — prefix/suffix tests
  • s.find(x) — index of a substring (-1 if absent); x in s — simple test
  • s.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.

Step 2

Try it yourself

Blank · autosaved

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”.

PYexample.py
+ Enter to run
Output appears here…
Step 3

Pass the challenge +30 XP

Blank · autosaved

Take the starter sentence, and print it as a slug: lowercase, words joined by hyphens. Expected: learn-python-the-fast-way

Target output
learn-python-the-fast-way
PYchallenge.py
Run your code to check it…
Step 4

Check your understanding

1. What does "-".join(["a", "b", "c"]) return?
2. "hello world".split() splits on…
Last step

Your notes (saved on this device)

Tip: use and to move between lessons, K to search everything.

Your next ten minutes

Write Python that does something useful.

Start free. No install, no card, no passive video marathon.

Start learning free → Explore the path