title: Adding a Prepend Method to a Linked List Class
body: <p>I am currently working on a class project involving linked lists and python. Currently, I am trying to create a prepend function for said linked list. My current code is throwing a recursion error. Here is my code:</p>
  <p>Node definition:</p>
  <pre><code>class Node:
      def __init__(self):
          self.data = None
          self.previous = None
          # introduce a 'next' node for doubly linked list
          self.next = None
  
      def get(self):
          return self.data
  
      def getPrev(self):
          return self.previous
  
      def setPrev(self, previous):
          self.previous = previous
  
      def set(self, data):
          self.data = data
  
      def getNext(self):
          return self.next
  
      def setNext(self, next):
          self.next = next
  
      node = property(get, set)
      prev = property(getPrev, setPrev)
      next = property(getNext, setNext)
  </code></pre>
  <p>Here is the List function w/ append and broken prepend function:</p>
  <pre><code>class SList:
      def __init__(self):
          self.tail = None
          # introduce 'head' node for double link
          self.head = None
  
      # appends to tail of list
      def Append(self, data):
          pdata = Node()
          pdata.node = data
          if self.tail is None:
              self.tail = pdata
          else:
              pdata.prev = self.tail
              self.tail = pdata
  
      # prepends to head of list
      def Prepend(self, data):
          pdata = Node()
          pdata.note = data
          if self.head is None:
              self.head = pdata
              pdata.step = self
          else:
              previous = self.head
              previous.step = pdata
              pdata.head = previous
              pdata.step = self
              self.head = pdata
  </code></pre>
  <p>The recursion error occurs at line 29 which is the setNext function:</p>
  <pre><code>def setNext(self, next)
      self.next = next
  </code></pre>