Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement