I am learning stacks for the first time. Below is the solution and URL
The question I have is this. The line “self.top_item = None”. self.top_item seems to be an instance of class Node, but why is it not written like “self.top_item = Node(value)” with value set to default of None?
Even though it is written “self.top_item = None”, below it has the attribute of class Node, “self.top_item.get_value()”. How is this so?
from node import Node # Add your Stack class below: class Stack: def __init__(self): self.top_item = None def peek(self): return self.top_item.get_value()
You must elect a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility
When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!
If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!