Lurker News
Back to discussion

Comment by peterkelly

peterkelly1 reply#
It's when you swap the left and right branches of every node, e.g.:

    def invert(node):
        if node is not None:
            left = invert(node.left)
            right = invert(node.right)
            node.left = right
            node.right = left
        return node
aldanor2 replies#
Or simply

    node.left, node.right = map(invert, (node.right, node.left))
quietbritishjim#
Coalescing those four lines onto one is fine, but writing:

    map(invert, (node.right, node.left))
is definitely not simpler than:

    invert(node.right), invert(node.left)
peterkelly#
Indeed - I just wanted to write it in a form that could easily be mapped to languages which don't support multiple simultaneous assignments :)