def reverse_linked_list(head): previous, current = None, head while current: # temporarily store the next node next = current.next # reverse the current node current.next = previous # before we move to the next node, point previous to the # current node previous = current # move to the next node current = next return previous