Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


Or simply

    node.left, node.right = map(invert, (node.right, node.left))


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)


Indeed - I just wanted to write it in a form that could easily be mapped to languages which don't support multiple simultaneous assignments :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: