Counting Letters

20-minute lesson · module-lab-counting-letters

You are previewing this course as a guest

Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.

Sign in

Counting Letters

20-minute lesson · module-lab-counting-letters

  • Build a dictionary by accumulating counts inside a loop.
  • Recognize when a single-purpose counter generalizes into a tallying dictionary.
  • Handle keys that may or may not already exist in a dictionary.

Source attribution

Status: adapted

How to Think Like a Computer Scientist: Interactive Edition source · Labs / Counting Letters

Adaptation notes. Reading rewritten in our voice. Generalizes the single-letter counter pattern from the source lab into a full character-tally dictionary. Hidden tests are newly authored and check both populated and edge-case strings.

License notes. Original lab is GNU FDL 1.3 (Brad Miller and David Ranum, 2011). No verbatim text from the original is reproduced here.