Code Review

    def remove_element(self,index):
       if index<1:
        print("Invalid Index, Enter a Number  < = 1 ")
    
       elif index ==1:
          current = self.head
          self.head = current.nextnode
       else:
          current = self.head
          count = 0
          while count<index:
              prev_node=current
              current = current.nextnode
              count+=1
          prev_node.nextnode = current.nextnode

What wrong with the above code
It throws an Error saying " NoneType has no attribute nextnode. "

Should this be tested first to be sure it is not None (tail node)?

1 Like