Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Introduction to Data Structures!

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
In the previous video we created the outlines of a linked list but without the ability to add nodes it's not really a list. Let's define an add operation to prepend nodes
Code Snippet for repr Function:
def __repr__(self):
"""
Returns a string representation of the list.
Takes O(n) time
"""
nodes = []
current = self.head
while current:
if current is self.head:
nodes.append("[Head: %s]" % current.data)
elif current.next_node is None:
nodes.append("[Tail: %s]" % current.data)
else:
nodes.append("[%s]" % current.data)
current = current.next_node
return '-> '.join(nodes)
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
JASON LEE
17,352 Points1 Answer
-
Timothy Tseng
3,292 Points1 Answer
-
Stephan Stylianides
1,317 Points1 Answer
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up