...

Chapter 17 - Python Quest

Many-Branch Trees

Use children lists to inspect, traverse, search, group, and grow trees with any number of branches.

XP
0Level 1
Stars
0/15quest stars
Combo
0clean runs
Rank
Seed0/160 Python score
Reading a multiway node's children

Festival Direct Branches

100 XP

A festival map starts at one hub whose signs can point toward two, three, or many nearby areas. The guide only wants the places one step away.

Write direct_children(root) so it returns the values of root's immediate children from left to right. Do not include grandchildren. Return [] when root is None or has no children. The judge gives root as a TreeNode with value and children attributes.

Sample checks

direct_children(root)returns["Games","Snacks","Stage"]
root
root: HubHubroot-0: GamesGamesroot-1: SnacksSnacksroot-2: StageStageroot-0-0: PinballPinballroot-0-1: KartsKartsroot-2-0: LightsLights

Explanation: Hub has exactly three direct children in order: Games, Snacks, and Stage; Pinball, Karts, and Lights sit another level down

direct_children(root)returns[]
root
root: SoloSolo

Explanation: Solo is a real root node, but its children list is empty, so there are no one-step destinations to place in the answer

Hint

Hints are ready when you want one.

Lesson reference

Review: Loop through one node's children list

Your Python

direct_children

Loading editor

Judge

Ready

0/5

Run your code when it feels ready.