• + 1 comment

    I like this solution, simple and elegant.

    In python you can switch variables in a single line like shown above, so the code goes through each node at a time reversing the connections until you hit the final node.

    The last node returned would be the final one encountered, which is now the first element.