Lecture 10 — Strings Under the Lens

Position in the course

This is lecture 10 of 32. It belongs to the course arc described in the course outline and uses the standard interactive case method: display, attempt (5 minutes), discuss, reveal, name the technique.

Learning objectives

By the end of this lecture students can do all three under time pressure, which is what the four cases exercise.

Prerequisite knowledge

Before this lecture: Lecture 04 + Lecture 09 — Python basics and iteration

Assumed fluencies:

Preparation task: Solve cs-038 by hand with paper slices.

Detailed topic outline

Core (mandatory):

  1. string immutability and slicing
  2. character classification
  3. parsing with split/join
  4. normalisation before comparison

Extension (optional enrichment):

  1. building strings efficiently
  2. palindromes and two-ended scans

Case sequence

CaseTitleDifficulty
cs-037Username AuditorBeginner
cs-038The Reversal FamilyFoundational
cs-039Template Mail-MergeIntermediate
cs-040The Anagram DetectorAdvanced

Display each case full-screen from the student page (cases cs-037–cs-040); instructor pages cs-037–cs-040 under case-studies/instructor/ hold the full solutions, reveal guides, and discussion prompts.

Timing plan (120 minutes)

MinutesSegment
0–10Framing: where this fits; recall of the previous lecture
10–30Case 1 (cs-037): 5-minute attempt, then discussion and reveal
30–50Case 2 (cs-038): same rhythm
50–70Case 3 (cs-039): same rhythm, harder case
70–75Break
75–100Case 4 (cs-040): same rhythm, hardest case
100–115Synthesis: name the techniques; misconceptions check
115–120Exit questions, homework, next-lecture preview

Timing flexes with the room: if a case ignites the class, let the discussion run and compress the synthesis; if the attempts stall, harvest partial attempts rather than extending the clock.

Worked examples

Instructor demonstration to open the lecture: Audit one bad username (cs-037) rule by rule on the board, in the exact order the rules must run, and show why order matters.

Classroom activities

#ActivityMinutesFormat and prompt
1Character desk check6A loop over a word is traced one character per desk; the class chants the state after each character.
2Normalisation ladder debate6For cs-040, argue which normalisation step is risky and give a pair of words that proves it.
3Anagram duel5Two pairs, one word each, fastest correct sorted-signature wins; losers explain their slower route.

Board plan

Instructor explanation notes

Reading the room. Strings punish sloppy thinkers delightfully: normalisation before comparison is the lecture's big idea. The normalisation ladder is drawn once and reused all term.

Running the reveal. Beginners should work one character at a time physically; advanced students meet the two-ended scan that lecture 19 formalises.

Lecture focus. One sentence to repeat verbatim: Normalise before you compare; slices before loops.

Common misconceptions

Each case's instructor page lists the specific wrong turn to expect; the reveal should address it by name.

Student practice exercises

Core:

  1. Write the normalisation ladder for a case-insensitive, space-blind anagram check.
  2. Parse 'Doe, Jane; Mathi, Aron' into two records using split only.
  3. Hand-slice your way through cs-038's reversal family for 'lecture'.

Enrichment (optional):

Formative assessment

Exit questions (choose one; answer on a card in 60 seconds):

  1. Why normalise before comparing strings? Expected: so equal-meaning strings compare equal (case, spaces, order)
  1. What does immutability of strings imply for building output? Expected: each change builds a new string; accumulate in a list and join
  1. When is slicing clearer than a loop? Expected: when the operation is positional (reverse, prefix, step) rather than conditional

Cards are skimmed before the next lecture; three answers become the framing. Persistent wrong answers route students to the review stations of lecture 16 or to office hours.

Homework and preparation

Learning-outcome mapping

Differentiation