SECTION 13 / 24

Turn a word into a character list

1 min read
explode("specially") produces [s,p,e,c,i,a,l,l,y]. A word can be one string or a list of characters, depending on the operation.
explode("specially") produces [s,p,e,c,i,a,l,l,y]. A word can be one string or a list of characters, depending on the operation.
REAL COURSE DATA · BUILD AND UNPACK LISTS

Explode a word into characters

Follow one occurrence at a time. Choose another input to test empty lists, repeated IDs and different parameters.

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, then step through the list. The original course records remain unchanged.

A word stored as one field can be unpacked with explode into a character sequence. explode("It") gives ["I","t"]. You can now use foreach, first, rest, last and init on the characters just as you did on student IDs.

Representations have levels. ["Monday","school"] contains two word strings. explode("Monday") contains six characters. A list of words is different from one flattened character list. Choose the representation that retains the information your question needs.

In this explorer, explode preserves case and punctuation. explode("eyes.") includes the final dot, while the alphabetic letter count is 4. A hyphen in fire-eyed is a character too. If a task wants only letters, make that cleaning step explicit rather than silently changing explode.

Try it yourself

What is length(explode("It"))?

Show explained answer

2: the characters I and t.

Try it yourself

Does explode automatically lowercase a word?

Show explained answer

No in this lesson. Case is preserved. The palindrome lesson explicitly lowercases its input as a separate convention.

Try it yourself

Why can stored LetterCount differ from character-list length?

Show explained answer

Punctuation or hyphens can be present in the string but excluded from a letter count. State which characters you count.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑