title: Python remove element from linked list
body: <p>Assume that there will be at least one element in the list when remov() is called, however, if there is only one element, then you will need to set head to None when that element is removed.</p>
  
  <pre><code>def remov(self): 
      current = self.head
      previous = current
      while current.get_next() != None:
          previous = current
          current = current.get_next()
      previous.set_next(None)
      return current.get_data()
  </code></pre>
  
  <p>I cannot return the right answer when there is only 1 element in the list. </p>
  
  <p>example:</p>
  
  <p><a href="https://i.stack.imgur.com/CeUbt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CeUbt.png" alt="enter image description here"></a></p>