How can I print all of the values of the nodes in my singly linked list using a while loop, or using the __iter__ magic method?
<p>If I have created a linked list of nodes which have a <code>value</code> attribute, is there a way to print all <code>value</code> attributes for all nodes in the linked list using a while loop?</p>

<p>[Edit] Also, how might I invoke the <a href="http://www.ironpythoninaction.com/magic-methods.html" rel="nofollow"><strong>iter</strong> magic method</a> so that I can iterate and print over the linked list? How also might I create a method that allows for additions, at the beginning, end, or before or after a certain object?</p>

<p>(I apologize if there is something basic, conceptually, that I'm missing in my understanding)</p>

<p>Below is the code for the nodes and singly linked list I've got setup, and you'll see that I've printed each value for each node at the bottom. However, I wasn't sure if there was a simple way to print all values easily, rather than listing each one:</p>

<pre><code># node class
class Node(object):
    def __init__(self, value):
        self.value = value
        self.next = None

# singly linked list class
class SinglyLinkedList(object):
    def __init__(self):
        self.head = None
        self.tail = None

linked_list = SinglyLinkedList()
linked_list.head = Node('Alice')
linked_list.head.next = Node('Chad')
linked_list.head.next.next = Node('Debra')

print linked_list.head.value, linked_list.head.next.value, linked_list.head.next.next.value
# is there a way to print all values for `linked_list` easily?
</code></pre>

<p>Thank you Stack Community for your help and for reading!</p>