Singly-linked list/Element definition: Difference between revisions

Content deleted Content added
Logo
Line 244:
The Node class implements also iteration for more Pythonic iteration over linked lists.
 
<python>class Node:
<pre>
class Node:
def __init__(self, value, next=None):
self.value = value
Line 253 ⟶ 252:
while node:
yield node
node = node.next</python>
</pre>
(Note that in Python you would always use the built-in list structure for this task, except for the specific case, such as this, when you are asked to show how you might implement the function without using the list type).