[Tutor] Tree again: iterator, yield, increase (treelib)
cs at cskk.id.au
Sat Oct 14 20:40:36 EDT 2017
On 14Oct2017 17:44, Chris <chris2014 at postbox.xyz> wrote:
>3. It seems that nid is initialized in get_iter, Line 218 
>4. nid is passed as parameter to __get_iter and the other
>5. the node with the id nid is fetched in line 222.
>6. In Line 190 there's a loop.
>I don't understand what increments nid or what makes the __get_iter
>function loop through the self._nodes dictionary defined in Line 106?
>Couldn't the __get_iter function iterate another list or dictionary?
>Which line says that you want to get every Node in self._nodes?
"nid" is not a counter, it is a node id, a key into the dictionary.
The loop starting on line 240 advances through all the immediate children of
the current node, and calls __get_iter using each child's identifier as the
"nid" parameter. In this way the whole tree is traversed.
Cameron Simpson <cs at cskk.id.au> (formerly cs at zip.com.au)
More information about the Tutor