title: Trying to Quicksort a linked list in python
body: <p>my professor has asked me to perform a Quicksort for a linked list. It is getting quite confusing as all the recursion and links are still very new to me. The issue seems to be with something unintentionally being assigned as None
  This is my code so far:</p>
  
  <pre><code>class Node:
      def __init__(self, d, n):
          self.data = d
          self.next = n
  
  
  class LinkedList:
  
      def __init__(self):
          self.head = None
          self.length = 0
  
      def append(self, d):
          if self.head == None:      
              self.head = Node(d,None) 
          else:
              ptr = self.head
              while ptr.next != None:
                  ptr = ptr.next
              ptr.next = Node(d,None)
          self.length += 1
  
      def merge(self,other):
          ptr = self.head
          while ptr.next != None:
              ptr = ptr.next
          ptr.next = other.head
  
      def removeVal(self, d):
          if self.head == None:
              return
          if self.head.data == d:
              self.head = self.head.next
              self.length -= 1
          else:
              ptr = self.head 
              while ptr.next != None:
                  if ptr.next.data == d:
                      ptr.next = ptr.next.next
                      self.length -= 1
                      break
                  ptr = ptr.next  
  
      def sort(self):
          if self.head!=None:
              pivot=self.head.data
              self.removeVal(pivot)
              smaller=LinkedList()
              other=LinkedList()
              ptr=self.head
              while ptr.next!=None:
                  ptr=ptr.next
                  if ptr.data&lt;pivot:
                      smaller.append(ptr.data)
                  else:
                      other.append(ptr.data)
              smaller.sort()
              other.sort()
              self=smaller
              self.append(pivot)
              self.merge(other)
  
  
  ls = LinkedList()
  ls.append(0)
  ls.append(1)
  ls.append(3)
  ls.sort()
  
  </code></pre>
  
  <p>Running this gives the following error</p>
  
  <pre><code>Traceback (most recent call last):
    File "main.py", line 71, in &lt;module&gt;
      ls.sort()
    File "main.py", line 58, in sort
      other.sort()
    File "main.py", line 51, in sort
      while ptr.next!=None:
  AttributeError: 'NoneType' object has no attribute 'next'
  </code></pre>
  
  <p>Any help would be very much appreciated</p>