Which fix removes the bug?
def walk(node, seen=set()):
seen.add(node.id)
for c in node.children:
walk(c, seen)
- Default to
Noneand create it inside - Default to
setand create it inside - Return
seenat the end of the walk - Change
seen.addtoseen.update
The default set is created once, so a second top-level walk still sees the first one's ids.
Play Problem Solving ▸