SECTION 01 / 28

A paragraph can be a list of lists of lists

1 min read

Last week, a pair was a list with two elements and a triple had three. Nested lists can also contain inner lists of different lengths. A paragraph can contain sentence lists; a sentence can contain word lists; a word can contain character lists. Each level answers a different question.

Paragraph → sentences → words → characters. The small illustration includes an extra example sentence; the lab uses the original course paragraph.
Paragraph → sentences → words → characters. The small illustration includes an extra example sentence; the lab uses the original course paragraph.
REAL COURSE DATA · SORT, GROUP AND VERIFY

Unpack paragraph → sentence → word

Follow the selected procedure. Change a field, tie rule or weekday and explain why the result changes.

Ready

CURRENT RECORD / VALUE

Ready to begin

No records have been processed. Start with Next step.

What we remember

Processed
0

Predict the next change. Keep track of which list level, field and position convention the procedure uses.

Paragraph = [Sentence1, Sentence2, ...]
Sentence1 = [explode("It"), explode("was"),
             explode("Monday"), explode("morning.")]
# first(Paragraph) is a sentence list
# first(first(Paragraph)) is a character list for its first word
# first(first(first(Paragraph))) is its first character

These expressions depend on the representation. Our original dataset stores word RECORDS with a Word field, not already-exploded character lists. For that version, get the first sentence’s first word record, read its Word field, then explode it. A number such as a student ID cannot be unpacked with first as though it were a list.

The original paragraph has five sentence groups of 4, 7, 8, 21 and 25 word cards. We use terminal full stops in these supplied cards to build the groups once, then reuse the sentence lists. This is a dataset convention, not a complete sentence splitter for abbreviations, quotes or general English.

Try it yourself

If the outer paragraph contains five sentence lists, is its length 65?

Show explained answer

No. Its outer length is 5. The total word-card count across those sentence lists is 65.

Try it yourself

Can you always call first three times on an object?

Show explained answer

No. Each intermediate result must be a non-empty list with the expected meaning. A scalar or an empty list has no first element.

Try it yourself

Why group sentences once?

Show explained answer

Later sentence-level tasks can reuse that structure instead of repeatedly searching for punctuation boundaries.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑