4uhpyg
Last Updated: February 25, 2016
·
809
· purak
Fe0a1519fcf6d2efd7f1a0bbc20660d2

Linked List in Python

A Linked List implementation in Python:

class LinkedList(object):
    def __init__(self, value=None, next=None):
        self.value = value
        self.next = next


ll = LinkedList

my_ll = ll(value="First Value", 
        next=ll(value="Second Value", \
            next=ll(value="Third Value")))

print("Values:")
print my_ll.value
print my_ll.next.value
print my_ll.next.next.value

print("Next items:")
print my_ll
print my_ll.next
print my_ll.next.next

The result of this code like that:

Values:
First Value
Second Value
Third Value

Next items:
<__main__.LinkedList object at 0x22babd0>
<__main__.LinkedList object at 0x22bab90>
<__main__.LinkedList object at 0x7f2aaadf3450>
Say Thanks
Respond