PythiloLesson 12 of 32 · progress kept in this browser

Reverse a linked list in place

A singly linked list stores each value with a pointer to the next node. Reversing it means turning every arrow around. Three names track the work: the previous node, the current one and the next one you are about to lose.

class Node:
    def __init__(self, value, next=None):
        self.value, self.next = value, next
head = Node(1, Node(2, Node(3)))
Your task

Node(value, next) is provided. Write reverse(head) that reverses the list in place and returns the new head (None for an empty list).