$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #111

Which fix removes the bug?

def walk(node, seen=set()):
    seen.add(node.id)
    for c in node.children:
        walk(c, seen)
  1. Default to None and create it inside
  2. Default to set and create it inside
  3. Return seen at the end of the walk
  4. Change seen.add to seen.update
The default set is created once, so a second top-level walk still sees the first one's ids.
Play Problem Solving ▸