──────────────────────────────────────

21. The Message Sorting Desk · Clean Names Without Losing Letters

Use casefold and whitespace normalisation for consistent comparison.

Lesson files · lessons/text-automation/normalise-text

Before you start
- Split a string into words and join those words with a separator.
- Use lower() to compare text by letter case.

By the end
- Compare two names using casefold() and consistent spacing.
- Use a name with an accent to explain why a report can keep the original spelling for display.

Where you can use it
Compare club-register entries after standardising case and spacing, then put the original names on the badges.

Use one space between words by splitting and joining the text. Use casefold() for a case-insensitive comparison. For example, it turns ß into ss, so Straße and STRASSE compare equal after folding. Keep the original spelling for display.

Predict
Does normalising whitespace remove the accented é?
- No.
- Yes.

Worked example (example.py)

name = "  Café   Club  "
print(" ".join(name.casefold().split()))


Example result
café club

Read two lines and print True when their normalised forms match, or False otherwise.

Starter program (starter.py)

name = "  Café   Club  "
print(" ".join(name.casefold().split()))


Hint
Write clean(text) once and call it for both lines.

Case 1. Try the sample
Input
 Café  Club
café club
Expected output
True

Case 2. Actually different
Input
Café Club
Music Club
Expected output
False

Case 3. Casefold maps ß to ss
Input
Straße Club
STRASSE CLUB
Expected output
True

Stretch
After printing the comparison, print the first name with its original spelling.

Reflect
Why might you still show the original name on screen?

Check your prediction
No. Whitespace processing removes whitespace around words. It preserves the characters inside them.
