FAQ: Linked Lists: Python - Linked List Implementation III

Hi @stewiegreen, and welcome to the Codecademy Forums!

In your posted code, the header line of remove_node is not indented at all. In that condition, remove_node would be interpreted as a global function, rather than as a method belonging to any class. In your actual code, is that line indented?

yes, in my code it is indented.

here is the whole class and it still gets this error:
“Did you remove your remove_node() method accidentally?”

class LinkedList:
  def __init__(self, value=None):
    self.head_node = Node(value)
  
  def get_head_node(self):
    return self.head_node
  
  def insert_beginning(self, new_value):
    new_node = Node(new_value)
    new_node.set_next_node(self.head_node)
    self.head_node = new_node
  
  def stringify_list(self):
    string_list = ""
    current_node = self.get_head_node()
    while current_node:
      if current_node.get_value() != None:
        string_list += str(current_node.get_value()) + "\n"
      current_node = current_node.get_next_node()
    return string_list
  
  def remove_node(self, value_to_remove):
    current_node = self.get_head_node
    if current_node.get_value() == value_to_remove:
      self.head_node = current_node.get_next_node()
    else:
      pass

This line in the remove_node method does not perform its designated task, because the get_head_node method is not actually being called:

    current_node = self.get_head_node

The intended method call must include parentheses, even though there are no arguments to be passed.

EDIT (September 15, 2019):

The message regarding removing your remove_node() method accidentally is actually from Codecademy’s submission correctness test (SCT) for this exercise, rather than from the Python interpreter. Though you did not remove that method, the SCT did not find a properly functioning remove_node() method, and issued a somewhat misleading message about that.

yup, that solved it. thanks

1 Like

Is there any advantage to using the getter and setter methods over just referencing the class’s arguments?
For example, if you had to set a new “next_node” is there a difference between doing it like this:
new_next_node = my_node.next_node
or like this:
new_next_node = my_node.get_next_node()

Might just be a style thing, but just wondering!
Thanks!