I assume you still have a reference to your head_node somewhere or you’d not be able to access your list at all, self.head_node perhaps? The reference count is for references to the object itself, not what objects that object subsequently refers to or you’d never be able to remove anything. So if b points to c but a does not point to b (and nothing else does either) then it should be marked for garbage collection regardless of the fact b still points to c.
If you’re curious what happens when objects refer to one one another (cyclic references and such) but all accessible references to those objects have been removed it gets a bit more complex. You can check this description on the mechanism if you’re curious- https://devguide.python.org/garbage_collector/
thanks a lot , that clarifies it. Yes, it is not symmetric with the head_node since it is pointed to by something, probably, self.head_node that keeps the list “alive”.
thanks again
Maybe it’s out of topic. What should I do, if I want to delete the values in LinkedList. while in the LinkedList, there are several nodes that have the same value. How do I delete all nodes that match the value I want when calling the remove_node method. Here is my code.
From the results above, it can be concluded, we have to delete the values from the nodes one by one. How do I if I want to delete all nodes with the value I gave to the remove_node method. For example, I want to delete all nodes with a value of 70. The result will be when we run remove_node (70) then the output of nodes with a value of 70 will be deleted.
My code cannot be verified and I have being trying for hours. I cant proceed without verifications. Is there any server problem? my connection is fine.
Please post your code (and format it according to this post) and describe the exact issue you are having (any error messages, parts you aren’t sure about, etc.).
If you are having connectivity issues, see this post.
I was checking the solution provided and the solution seems to break if we pass in a value which does not exist in the list…
Here is how I modified the code to ensure that even if the value is not in the list, it does not result in a run time error, I guess the other way would be to add a try, except block
Whoever created this exercise seems to completely miss the notion of step-by-step instructions. I feel like if I have been just taught an alphabet and immediately asked to write an assay. What is missing is more prior exercises on the structure of linked lists and how to reference different nodes and traverse the list. I have to struggle for days and look for explanations on different resources. That makes me wonder if being on codecademy is even worth it?
Suddenly felt that I had to say it. We come here with such a different base of knowledge, somebody says that the course “feeds with a teaspoon”, somebody says that the explanation is too week… I haven’t try any other resourсes to study, so I have nothing to compare it with, but each time I feel the deepest respect for all the creators of codecademy for the patience and the ability to maintain a line without going too deep in details and not slipping too much on the surface, to teach people who want to study. It’s like in real life, you never find people who think exactly like you, lukily for us… But one can learn something from any person SORRY, SORRY, SORRY, it’s absoulutly our of topic!!! With great respect…
I still don’t understand why the instruction asked to set the current_node = None to exit the loop. Assuming we have a(head) -->b–>c, and after we find (current_next_node) b value == value_to_remove, we link a -->c, so current node is still a. If we set current value as None, does it messed up a value??? Could anyone please explain this to me?
And since I was not sure writing current_value = none, I wrote the return in order to exit the loop instead. It did checked final step of instruction as completed, but could anyone tell me if this way work?
Because the while loop condition is current_node, as long as current_node is truth the loop will continue to iterate. By setting current_node to None, we exit the loop since None is falsy. It doesn’t mess up the value, because in this case pass-by-object-reference is used (good explanation here).
Returning would also work, but if at any point in the future you wanted to add more code inside the method after the while loop, it might not function that way you would want.
100% agreed. I had to go to Youtube for help and it’s wasting a lot of my time to learn what Codecademy didn’t properly teach in respectable length. Just felt rushed and then pushed a huge block of steps into one paragraph and told us to parse it out with vague instructions.
Why doesn’t Codecademy make these linked list lessons into video? It’s really hard to parse out current_node.set_next_node(next_node.get_next_node()) as a total beginner…like wow. What an awful way to present this already confusing content.
With all due respect, this has been one of the worst lessons I’ve come across on Codecademy. Perhaps in the future I’ll think of this lesson as beginner level, but RIGHT NOW, this is hard!
I was fine with the previous chapter of Nodes. I was able to draw the nodes out on a paper and follow through each step of the code, but once I got into Linked List lesson, I couldn’t follow.
I often got lost on what node I am on because all I see is repetitive words “node, next.node, new_node, Node…” and a vague set of instructions of what I’m supposed to do. I kept losing focus on what my purpose is…even when I retrace my steps.
I and a huge part of Codecademy community learn better when we actually visualize the logical steps taken for each step of the code.
I’m sure the lesson afterwards is going to be much more complicated but if this is level of explanation we are getting at this stage, then we are pretty much set up for failure. Why even bother with Codecademy in the first place?
My advice is for Codecademy to invest on a couple of visual and motion designers (happy to volunteer) to communicate this technical jargon. It can be an interactive lesson or even a simple video or gif (no image).
P.S I participated in one of your user research interviews about a year ago, I’m happy to assist again.
Half way through doing this lesson, I realised that using the get_next_node() and get_head_node() functions could be completely bypassed by simply referencing the variables themselves.
Is there any technical issues with doing this in the long term or is it just there for good practise?
Hey, I too thought about that too much and then got that it’s simply to stop the while loop. As it is the end of the program and after it, we are not using current_node so doing this step current_node = None, will end the while loop without affecting the program.