SECTION 09 / 31

Build a word-length frequency dictionary

1 min read
The supplied 65 word cards contain 11 of length 2, 16 of length 3 and 10 of length 4.
The supplied 65 word cards contain 11 of length 2, 16 of length 3 and 10 of length 4.
REAL COURSE DATA · KEYS, COUNTS AND CONNECTIONS

Build the word-length frequency dictionary

Follow the dictionary as its keys and values change. Predict each lookup or update before revealing the next step.

Ready

CURRENT RECORD / VALUE

Ready to begin

No records have been processed. Start with Next step.

What we remember

Processed
0

Predict the next key, whether it already exists, and the value that will be stored.

lengthCount = {}
foreach X in words {
    k = X.LetterCount
    if (isKey(lengthCount,k)) {
        lengthCount[k] = lengthCount[k] + 1
    }
    else {
        lengthCount[k] = 1
    }
}
LetterCount234567891011
Word-card frequency1116102744542

Use the provided LetterCount field. The Word field retains punctuation, so counting the visible characters of “morning.” is a different calculation. Repeated word occurrences each count once. There are 10 observed length keys and 65 word records. The most frequent length is 3, with 16 occurrences.

A bar chart can put observed lengths in numerical order and frequencies on the vertical axis. That ordering is a presentation step; it does not require dictionary storage to be sorted. A missing length key means no observed occurrence under this counting rule.

Try it yourself

What does lengthCount[3]=16 mean?

Show explained answer

Sixteen word cards have supplied LetterCount 3. It is not the third word’s length.

Try it yourself

What should the frequencies sum to?

Show explained answer

65, the number of word cards.

Try it yourself

If “the” appears many times, do we count it once?

Show explained answer

No. This is a frequency of word-card occurrences, not a count of distinct spellings.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑