Course outline · 0% complete

0/32 lessons0%

Course overview →

Project: Word Counter

lesson 10-2 · ~13 min · 31/32

The tool

Given a line of text, report three things:

  1. how many words it has,
  2. how many different words it has,
  3. which word appears most often.

The ingredients, all yours already: split() and set() from lesson 7-3, the dict counting pattern from lesson 7-1, and a find-the-max scan like lesson 6-3. One new touch: lowercase the text first with .lower() (lesson 2-2) so The and the count as the same word.

Code exercise · python

Part 1: totals. Run it. The stdin line is the text being analyzed.

Quiz

Why lowercase the text before counting words?

Code exercise · python

Part 2, your turn: the most common word. Build the counts dict with the get-pattern from lesson 7-1, then scan `counts.items()` for the biggest count, and print like `the appears 3 times`.

Problem

Run this lesson's tool in your head on the line `up down up down up`. How many total words and how many unique words does it report? Answer as two numbers separated by a space.