🐸

The Binding Spell

The Data Tinkererpython-data-tinkerer-03-the-binding-spell
Reward: 85 XP
|

The Binding Spell

In the last lesson, we split the lantern clue into separate word pieces. Now those pieces float around Hoppy like loose runes, not yet a clue that can be read aloud.

If Hoppy wants to share the clue with the group, the scattered shape is not enough. This time the spell is not another split. It is a light binding thread that ties the word pieces back into one sentence.

First, watch it turn back into text

The important moment in this lesson is not a definition. It is seeing another shape change: one line still looks like a list with brackets and commas, and the next line becomes a readable sentence again.

pieces = ["moss", "path"]

print("Word list:", pieces)

tiny_message = " ".join(pieces)
print("Bound sentence:", tiny_message)

The first line looks like loose pieces. The second line becomes one clue again. A list is not the final form here. It is just a useful middle stop in the workshop.

Use join() to bind the pieces back together

When you already have a group of string pieces and want one string again, join() is the move you want.

The part that often feels strange at first is " ".join(words). That " " in front is not decoration. It is saying, “Put one space between each piece while you glue them together.”

1
Find the line that rebuilds the sentence

The starter already shows the list of pieces and the output spot. The line you need to change is the one that creates bound_sentence.

2
Use join() to connect the word pieces

Replace the placeholder with the real binding move so bound_sentence becomes one new string with spaces between the words.

3
Run it and compare the two shapes

Look at the list first, then look at the rebuilt sentence. You should be able to feel that the split pieces became readable and shareable again.

Why is there a string in front?

Think of that tiny string in front as the glue. In this lesson, the glue is one space, so the result comes back as a normal sentence with a space between each word.

Suggested Solution
Expand
Solution:
words = ["follow", "the", "lantern", "path"]

print("Word list:", words)

bound_sentence = " ".join(words)
print("Bound sentence:", bound_sentence)
Advanced Tips
Want more? Click to expand

Programmers would say that split() often turns one string into a list, and join() turns a group of string pieces back into one string. You only need the names lightly for now. The main thing is feeling that this little split-and-bind loop works.

When a sentence feels too packed and you need to inspect pieces, use split(). When the pieces are ready and Hoppy needs readable text again, use join().

Loading...
Terminal
Terminal
Ready to run...