FAQ: Linked Lists: Python - Linked List Implementation III

Hello peoples,

I don’t mean to sound critical of this lesson, I’m only trying to understand what is the point of it?
I do not have a computer science background, so I have absolutely no context into which to put this lesson.

Is there a broader concept this is trying to teach?

I feel like I’m missing the entire value of the exercise. I was able to complete it, but I gained no understanding from it. ( I learn best if I know the general context of what i’m supposed to use something for(what does this tool in the tool box do and how do I apply it.). I can hammer a square peg into a round hole with a spanner wrench, but it’s not a good idea, a good use of time; or a proper use of the tool.

“When one teaches, two learn” – I can’t remember who this quote is from

1 Like

Nowadays, the linked list is a relatively esoteric data structure. You won’t really have much use for it unless you’re doing lower level programming. It’s usually used in contrast to an array(not to be confused with JS arrays which is equivalent to Python’s List). The data in an array has to be sitting next to each other in your system’s memory so it needs to have a set amount of memory allocated to it to fit the data. Linked lists on the other hand have pointers to the next data point which can be anywhere in system memory, so there doesn’t need to be any pre-allocated memory, it can grow or shrink with the data, which also makes it pretty efficient when adding/removing data. Why they’re teaching it here, it’s an important part of CS fundamentals. The knowledge learned here is important when working with more complex data structures and also opens more doors for what kind of projects you can work on in the future.

1 Like

Whe you know that the file that you want to delete is b. You have to put None as b’s value for deleting the node so instead of havig:
a–>c you will have
a–>c<–b (bacause you alredy deleted the conection between a and b)

" Add an else clause. Within the else clause:

  • Traverse the list until current_node.get_next_node().get_value() is the value_to_remove .(Just like with stringify_list you can traverse the list using a while loop that checks whether current_node exists.)
    • When value_to_remove is found, adjust the links in the list so that current_node is linked to next_node.get_next_node() .
    • After you remove the node with a value of value_to_remove , make sure to set current_node to None so that you exit the loop."

i think the part say-" Traverse the list until current_node.get_next_node().get_value() is the value_to_remove .(Just like with stringify_list you can traverse the list using a " make mistakes, cause its not the way to write the condition.
just write somthing like- keep the loop until it meet the value to delete…
and let the user think how to write the condition

What is the point of most of the methods ?
I mean…

node.get_value() == node.value
node.get_next_node() == node.next_node

Why using methods for that?

1 Like

I have the same question. It works just fine this way and it looks way clearer

What I understood is that sometimes we don’t have full access to a program, being for example on “read-only”. In some cases using methods is the only way you have to access the data of your object.

Hi i have two questions
First question about the stringify_list and head node
First we self.head_node = Node(value)
than that method:

def insert_beginning(self, new_value):

    new_node = Node(new_value)


    self.head_node = new_node

We create a new node and than we replace self.head_node with new node with new value
my question is how self.head_node stores a values like when add a 4 values and we use stringify_list method it will prints 4values how ?
my second question is why if we write that code:

def insert_beginning(self, new_value):
    self.head_node.value = new_value

it will return a nothing ?

Hey there.

Maybe its just me, but I’m finding the OOP and node lessons to be lacking in explanation and guidance for the exercises. It seems to go from “this is what a node is” to lets move throughout the list and delete nodes without any instruction on how to do so. I feel as though these lessons could be a little more thoroughly explained to prevent the confusion that is found in the preceding comments.


mate, totally agree with you!

1 Like

Thanks so much! I had done the same except missed the second else statement so kept getting stuck on an infinite loop!

First we self.head_node = Node(value)

Yes at first a linked list object ‘ll’ is created by calling the LinkedList class, ll = LinkedList(5) , which itself calls the Node class, self.head_node = Node(value).
Inside the LinkedList class a node object is created called ll.head_node.
ll.head_node has access to Node’s functionality so ll.head_node.value has a value of 5 and ll.head_node.next_node has a value of None. When the insert_beginning() method is called via ll.insert_beginning(4) a new node object is created called new_node. Initially new_node has a value of 4 and a next_node of None.

new_node.set_next_node(self.head_node) sets the new_node objects next_node to that of the head_node.

self.head_node = new_node then assigns the head_node with new_node and the former head_node is now the second node in the LinkedList ‘ll’.

As far as your second question is concerned I’m not quite sure but it seems as though
self.head_node.set_next_node(self.head_node) sets the head_node’s next_node to itself.

That’s a big part of it. While Python doesn’t exactly allow us to create private variables and methods like Java or C++, using getters and setters is still a way to control what a user or program has access to.
For example, you could put out an API of your linked list for other developers to use but you don’t want them to be able to change the values in the list. By not including a setter method, they wouldn’t know how to access the value variable to change it.

1 Like

I have the same question… Still don’t get it why we have to set current_node = None.

Probably better if you consider the intentions of what’s being done rather than some particular detail in the code. What should happen there? Is there repetition involved, when does that start when does that end?

When I hit the “Run” button, the program thinks forever. How can I overcome this problem or skip to the next stage?

Hello @method7269688012 and welcome to the Codecademy Forums!

Usually, this issue occurs when you have an infinite loop in your code. Double-check that you don’t have one.

I don’t think this is the case. I put print statements to check my program and the results print on the screen immediately (and correct), but the error message “Failed to test your code” appears after a very long time, and, needless to say, I cannot progress to the next stage. (see attached image)
Any suggestions?

I’m not sure what’s wrong then. Maybe trying copying your code, resetting the exercise, and running it again?

That helped! Thanks.

1 Like