There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Regarding Step 3, I’m not clear why using get_link_node() is necessary
Referring specifically to the (apparently correct) code below:
dots_data = yacko.get_link_node().get_value()
Why not just write 'dots_data = yacko.link_node.get_value()? We’ve already set the link node as an attribute of the class in the set_link_node() method.
Edit: In fact, I’m not sure what the point of the get_link_node() or set_link_node() methods are at all, when we can just ‘get’ and ‘set’ using regular dot notation with class attributes.
My best guess is that they want to expose all behaviour through methods.
I don’t agree, in my eyes it’s dead code that makes it harder to see what’s actually being done.
In this particular case you can’t tell the advantages, but the ‘get’ and ‘set’ methods are used in other programming languages in order to control the types of the data you pass to the instance variables. Say you have an instance variable ‘age’. If you didn’t set a ‘set’ method with ‘if’ statements, you would be able to enter a string. Sometimes it’s not necessary at all but people keep using the ‘set’ and ‘get’ method as good practice, I guess.
What about the second point in step 3 (of the fourth part of the lesson)? It asks how we can get the value of -wacko- from -yacko- but they are not immediately linked. However -yacko- is linked to -dot- and -dot- is linked to -wacko-.
Is there a way to to travel through -dot- with the -.get_link_node().get_value()-?
If you look at the Node methods, yacko.set_link_node(dot) sets yacko.link_node = dot. When you then call the yacko.get_link_node() what’s being returned is the object dot because that’s what yacko’s link_node is assigned to. So using the second .get_link_node() in the above code is just like writing dot.get_link_node() which as you already know is is linked to wacko.
yacko.get_link_node()#This returns yacko.link_node which is assigned to dot
The get_value() method returns the value of the object the method is called on. So, yacko.link_node().get_value() is like writing dot.get_value() which returns the value of the object dot. This value is then assigned to the variable dots_data.
We could just get the value of the object dot directly but the idea is to obtain the value by linking nodes together. Hope this helps.
Hello! I went around lots of discussion topics in the community forum and got here! My doubt is: WHY IS IT A BETTER APPROACH TO USE NODES AS UNDERLYING DATA STRUCTURES FOR MAKING STACKS AND QUEUES?! The Codecademy Instructions keeps asking, i have no such good reason why! Couldn’t i simply use normal Lists?!
I understood the complex way the implementation works! Is just that i need a reasonable explanation to WHY NODES (LINKED LISTS)?!
And also…Wouldn’t it be easier to do the implementation via ARRAYS?!
I think the answer is that linked-lists are being used to help you get familiar with how nodes work, but the data structures you can build with nodes can be much more complex than a simple list or an array.
I had the same exact question and this is the answer I was looking for but I just want to work through this expression. So, the first yacko.get_link_node() basically becomes dot because we set it to that earlier, then the second .get_link_node translates to dot.get_link_node() and so we are then getting the value from dot which we set dot’s link to wackos value. Thanks for the clarity!
Thank you a lot for the clarification, I have a question, why writing dots_data = yacko.get_link_node()
wackos_data=dot.get_link_node() doesn’t return yacko.link_node or wacko.link_node when I print: print(dots_data)
print(wackos_data)
I didn’t have a problem with the exercise, but I’m still trying to understand how we would use nodes and linked lists in the real world. Does any have an Idea?