Chapter 17 - Python Quest
Many-Branch Trees
Use children lists to inspect, traverse, search, group, and grow trees with any number of branches.
Festival Direct Branches
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"]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[]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
Judge
Ready
Run your code when it feels ready.
