Skip to content

Instantly share code, notes, and snippets.

@colinpollock
Created June 3, 2012 21:43
Show Gist options
  • Save colinpollock/2865134 to your computer and use it in GitHub Desktop.
Save colinpollock/2865134 to your computer and use it in GitHub Desktop.
class Node(object):
def __init__(self, data):
self.data = data
self.next_node = None
def __repr__(self):
return self.data
class List(object):
"""
>>> L = List()
>>> len(L)
0
>>> L.append(Node(47))
>>> len(L)
1
>>> L[0]
47
>>> L.append(Node(53))
>>> len(L)
2
>>> L[1]
53
>>> L.insert(0, Node(31))
>>> len(L)
3
>>> L[0], L[1], L[2]
31, 47, 53
"""
def __init__(self):
self.head = None
def insert(self, index, node):
"""Insert node before index."""
def append(self, node):
"""Append node to self."""
def __len__(self):
"""Return the number of nodes in self."""
def __getitem__(self, index):
"""Return the node at index."""
def __setitem__(self, index, node):
pass # do this later
def test():
import doctest
print doctest.testmod()
if __name__ == '__main__':
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment