Linked List Families!ΒΆ

What is a node again? Let’s see!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class Node:
    def __init__(self, content):
        self.content = content
        self.next = None

    def set_next(self, next_node):
        self.next = next_node

    def get_next(self):
        return self.next

Your first job is to rewrite this class using different names!

  1. The class should be renamed to “Person”

2. the internal variable content should be renamed to name 3. rename set_next to be set_next_person. 4. inside set_next, the variable next_node should be renamed to next_person

We are going to use this class to represent the Jetsons standing in line! It should pass the following test:

1
2
3
4
5
6
george = Person("George Jetson")
jane = Person("Jane Jetson")
judy = Person("Judy Jetson")

george.set_next_person(jane)
jane.set_next_person(judy)

What would happen if we did the following?

1
2
elroy = Person("Elroy Jetson")
jane.set_next_person(elroy)

When you have finished the code above and can answer this question, click here to go to the next page. The answer is there, so don’t peak!