3 ms·
That's not python specific. When you're running BFS, after visiting a node, you next visit each of that node's children. From a python-specific viewpoint, dequ
by Yen 9y ago
That's not python specific. When you're running BFS, after visiting a node, you next visit each of that node's children.
From a python-specific viewpoint, dequeue.extend appends a given list to the end of the queue. The first example will raise an exception, but the other two are perfectly valid, and their behavior isn't special to python - it's just asking whether you'll want to vi it this same node again, or the node's children.
Incidentally, it's not as if there's any standard library 'node' class with a children method. This was a structure they defined, but did not share the definition of.
- fenomas 9y ago> Incidentally, it's not as if there's any standard library 'node' class with a children method. This was a structure they defined, but did not share the definition of. Ahh, that makes things much clearer. Since they weren't otherwise mentioned, I supposed that "value" and "children" were properties of some existing Python collection object - and that the question was asking how "queue.extend" expected that collection to be passed in. I guess this is the inverse of a language-specific question - if one knows that "children" has no significance in Python then I suppose the question would be clearer.