LinkedLIst code gets different results on my machine than Codecademy

Hey folks, I’m working on the linked lists module in the Computer Science track - specifically the two pointer piece of it.

I’ve generally will work on my code using VS Code and then cut and paste it into the IDE on the website. I got this exercise working on my machine, but when I cut and paste it (modifying the import at the top to point at the LinkedList module in the LinkedList file appropriate for the Codecademy iDE insetad of the LinkedList module from a different file in VS Code on my machine), the program runs, and will give me a result, but it is an incorrect result in the Codecademy environment, while I get the correct result when I run it on my machine with VS Code.

Does anybody see why? Or know a way we can examine the LinkedList file the Codecadmy environment points to?

Thanks in advance. :slight_smile:

PS The Python version on my machine is 3.9.7

import inspect

Output (for your convenience):
class LinkedList:
  def __init__(self):
    self.head_node = None
  def get_head_node(self):
    return self.head_node
  def insert_beginning(self, new_value):
    new_node = Node(new_value)
    self.head_node = new_node
  def stringify_list(self):
    string_list = "<head> "
    current_node = self.get_head_node()
    while current_node:
      if current_node.get_value() != None:
        string_list += str(current_node.get_value()) + " "
      current_node = current_node.get_next_node()
    string_list += "<tail>"
    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()
      while current_node:
        next_node = current_node.get_next_node()
        if next_node.get_value() == value_to_remove:
          current_node = None
          current_node = next_node
  def find_node_iteratively(self, value):
    current_node = self.head_node
    while current_node:
      if current_node.value == value:
        return current_node
      current_node = current_node.get_next_node()
    return None
  def find_node_recursively(self, value, current_node):
    if current_node == None:
      return None
    elif current_node.value == value:
      return current_node
      return self.find_node_recursively(value, current_node.get_next_node())
1 Like

Oooh, super helpful, @midlindner - thank you!

I’ll continue to investigate.

1 Like

Also for checking the Python version:

import sys
import platform

Output (From the CC learning environment for the lesson you linked:

3.6.9 (default, Mar 15 2022, 13:55:28)
[GCC 8.4.0]