HELP! Removing and returning items


#1

I am working with doubly linked list and in my remove_element_at method I want to remove an element then return it but I keep failing 2 test cases. Here is my code and here are the test cases I am failing. I am not sure what I am doing wong.

def remove_element_at(self, index):
      if index > self.__size or index < 0 or index == self.__size:
          raise IndexError
      cur = self.__header.next
      if index == 0:
          element_to_return = self.__header.next
          self.__header.next = self.__header.next.next
      else:
          for i in range(0, index-1):
              cur = cur.next
          element_to_return = cur
          cur.next = cur.next.next
      self.__size -= 1
      return element_to_return.val

def test_remove_tail_leaving_one_returned_value(self):
    self.__string_list.append_element(3)
    self.__string_list.append_element(2)
    returned = self.__string_list.remove_element_at(1)
    self.assertEqual(2, returned)

def test_remove_middle_leaving_two_returned_value(self):
    self.__string_list.append_element(3)
    self.__string_list.append_element(2)
    self.__string_list.append_element(1)
    returned = self.__string_list.remove_element_at(1)
    self.assertEqual(2, returned)