🐸

The Pattern Trail

The Data Tinkererpython-data-tinkerer-29-the-pattern-trail
Reward: 150 XP
|

The Pattern Trail

Hoppy steps into a dim hallway and finds three clue tags pinned to the wall. At first they look messy, but after one careful look, each tag seems to repeat the same tiny shape.

That is the first move of a text detective: do not freeze just because the text looks messy. First check whether a repeated pattern is hiding inside it. Once you notice the pattern, the rest becomes much easier to open up.

Spot the repeated shape before you split

Some messy text is not truly shapeless. It is just not arranged like a clean table. A few clue fragments might still repeat one small form, such as marker:place. Once you see that, you can use the same move on every fragment.

bird:oak | bird:pine | bird:elm

pieces = "bird:oak | bird:pine | bird:elm".split(" | ")
marker = pieces[0].split(":")[0]
first_place = pieces[0].split(":")[1]
print(marker)
print(first_place)

This example only shows the feeling of “spot the repeated shape, then split it the same way.” It is not the full answer to today’s starter. In the real task, you will do the same move on a different clue note.

Today’s task: turn repeated clue fragments into one trail report

The starter already gives you a trail_note and builds fragments. Your job is to keep using the repeated marker:place shape, pull out the shared marker and the three places, then gather everything into trail_report.

1
Look at the shape of each fragment first

Run the starter and inspect trail_note and fragments. Before writing much code, confirm that every fragment looks like some_marker:some_place.

2
Use the first fragment to reveal the pattern

Use fragments[0] to grab the part before and after the colon. The front half gives you shared_marker, and the back half gives you one place.

3
Apply the same split to the other fragments

Reuse the same split(":") move to get second_place and last_place, then arrange all three places into a list called trail_places.

4
Gather the clue into trail_report

Finally, build one dict named trail_report from those values. This is what real text work often feels like: spot a pattern, split each piece, then gather the result into something clearer.

This lesson only trains one first move

We are not learning regex here, not handling complicated logs, and not turning this into pattern theory. We are only practicing one practical opening move: notice a repeated shape, then split it in the same way.

Suggested Solution
Expand
Solution:
trail_note = "torch:north | torch:east | torch:south"

print("Trail note:", trail_note)

fragments = trail_note.split(" | ")
print("Fragments:", fragments)

shared_marker = fragments[0].split(":")[0]
first_place = fragments[0].split(":")[1]
second_place = fragments[1].split(":")[1]
last_place = fragments[2].split(":")[1]
trail_places = [first_place, second_place, last_place]

trail_report = {
  "shared_marker": shared_marker,
  "first_place": first_place,
  "second_place": second_place,
  "last_place": last_place,
  "trail_places": trail_places,
}

print("Shared marker:", shared_marker)
print("First place:", first_place)
print("Second place:", second_place)
print("Last place:", last_place)
print("Trail places:", trail_places)
print("Trail report:", trail_report)
Advanced Tips
Want more? Click to expand

The main win in this lesson is not memorizing one syntax trick. It is building a text-detective instinct: first ask whether the text repeats a shape, then decide how to open it.

In the next lesson, you will carry that instinct into a more realistic log-style text and keep practicing “split the fragments, then pull the useful details.”

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