Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Recipe

Normalize text before comparing it

Use when: text typed by a person, or read from a file, has to be compared, searched, or counted

Goal: a cleaned copy that treats spacing, accents and case as unimportant, with the original kept for display

Taught in Text-processing patterns

  1. 1

    s.strip() removes spaces, tabs and line breaks from both ends.

    Example

    " Ada LOVELACE \n".strip() is 'Ada LOVELACE'.

    Why: stray whitespace at the edges is the most common difference between two "identical" answers.

  2. 2

    " ".join(s.split()) turns every run of whitespace into one space.

    Example

    " ".join("Ada LOVELACE".split()) is 'Ada LOVELACE'.

    Why: split() with no argument throws away every extra space, and join puts single spaces back.

  3. 3

    unicodedata.normalize("NFC", s) (after import unicodedata) combines letters and accent marks into one code point where one exists.

    Why: the same word can arrive with é as one code point or two (section 6), and the two never compare equal.

  4. 4

    s.casefold() on the copy you compare; keep the original for showing.

    Example

    "Ada LOVELACE".casefold() is 'ada lovelace'.

    Why: casefold() handles letters like ß that lower() leaves alone, and showing a person their own text unchanged is polite.