<jupyter_start><jupyter_text>Linked List Reversal  ProblemWrite a function to reverse a Linked List in place. The function will take in the head of the list as input and return the new head of the list.You are given the example Linked List Node class:<jupyter_code>class Node(object):
    
    def __init__(self,value):
        
        self.value = value
        self.nextnode = None<jupyter_output><empty_output><jupyter_text>SolutionFill out your solution below:<jupyter_code>def reverse(head):
    cur = head
    pre, nxt = None, None
    while cur:# watch out
        nxt = cur.nextnode
        cur.nextnode = pre
        pre = cur
        cur = nxt
    return pre #watch out
    pass<jupyter_output><empty_output><jupyter_text>Test Your Solution**Note, this isn't a classic run cell for testing your solution, please read the statements below carefully**You should be able to easily test your own solution to make sure it works. Given the short list a,b,c,d with values 1,2,3,4. Check the effect of your reverse function and make sure the results match the logic here below:<jupyter_code># Create a list of 4 nodes
a = Node(1)
b = Node(2)
c = Node(3)
d = Node(4)

# Set up order a,b,c,d with values 1,2,3,4
a.nextnode = b
b.nextnode = c
c.nextnode = d<jupyter_output><empty_output><jupyter_text>Now let's check the values of the nodes coming after a, b and c:<jupyter_code>print (a.nextnode.value)
print (b.nextnode.value)
print (c.nextnode.value)
d.nextnode.value<jupyter_output><empty_output><jupyter_text>So far so good. Note how there is no value proceeding the last node, this makes sense! Now let's reverse the linked list, we should see the opposite order of values!<jupyter_code>reverse(a)
print (d.nextnode.value)
print (c.nextnode.value)
print (b.nextnode.value)
print a.nextnode.value # This will give an error since it now points to None<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08222811671087533, 'fraction_numerical': 0.006896551724137931, 'mean_word_length': 4.224376731301939, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '62363', 'license': 'MIT', 'n_tokens_mistral': 610, 'n_tokens_neox': 599, 'n_words': 228, 'path': 'code/algorithms/course_udemy_1/Linked Lists/Problems  - PRACTICE/Linked List Reversal .ipynb', 'repo_name': 'vicb1/miscellaneous', 'size': '1885'}