4 ms·
I only looked at three questions, but two of them were entirely Python specific. Question 2 asks you to choose between: queue.extend(node) queue.extend
by fenomas 9y ago
I only looked at three questions, but two of them were entirely Python specific. Question 2 asks you to choose between:
queue.extend(node)
queue.extend([node])
queue.extend(node.children)
Sure, I could take a guess which one of those appends the contents of "node" to the end of "queue", but I'd be guessing about syntax, not programming.
After that, and question 3 about what happens when you assign to a function argument, I realized it was a Python quiz and stopped reading.
- ammon 9y agoThe intent was that node.children would be the giveaway. The question is about BFS, and you'll notice that only one of the answers references the node's children (in a sensible way). The intent was that that would be enough to answer it without knowing python queue syntax (for what it's worth, I know python well and don't have the deque API in my head)
- fenomas 9y agoThanks for the explanation, please see sibling comment for context. I think that a comment like # assume "node" is an object with "value" and "children" properties would make this question clearer.
- Yen 9y agoThat'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.