Singly-linked list/Traversal: Difference between revisions

m (Moved out of Sol by Task cat)
Line 40:
=={{header|Python}}==
 
<prepython>
lst = Node('A', Node('B'))
for node in lst:
print node.value
</prepython>
 
Any Python class can define ''next()'' and ''__iter__()'' methods so that it can be used with the normal ''for'' iteration syntax. In this example the "lst" could be an instance of any Python list, tuple, dictionary, or any sort of object which defines an iterator. It could also be a generator (a type of function which ''yields'' results upon each successive invocation). The notion of a "singly linked list" is somewhat more primitive than normal Python built-in objects.
Anonymous user