SHARE
TWEET

Untitled

a guest Feb 26th, 2020 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Node:
  2.     def __init__(self,value, next_node):
  3.         self.value = value
  4.         self.next_node = next_node
  5.     def __str__(self):
  6.         s = "current value is {}, next value is {}".format(self.value,self.next_node)
  7.         return s
  8.  
  9.    
  10. head = Node(2,None)
  11. head = Node(1,head)
  12.  
  13. print(head)
  14.  
  15.  
  16.  
  17. def reverse_list(head):
  18.     new_head = None
  19.     while head: # WHY DOES THIS LINE WORK?
  20.         head.next_node, head, new_head = new_head, head.next_node, head # look Ma, no temp vars!
  21.     return new_head
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top