title: Python: Remove element from list returns None
body: <p>According to this <a href="https://www.programiz.com/python-programming/methods/list/remove" rel="nofollow noreferrer">link</a> it should be easy to remove an element from a list. The example provided in the link works fine. In my use case I need a wrapper function that avoids the error from being returned if the passed list does not contain the element that should be removed.</p>
  
  <p>This is the code that I've come up with:</p>
  
  <pre><code>def filterval(ls,val):
      if val in ls:
          return(ls.remove(val))
      else:
          return(ls)
  </code></pre>
  
  <p>Strangely though, this code returns None in the following situation:</p>
  
  <pre><code>print(filterval([1,2,3,4,5],2))
  </code></pre>
  
  <p>Interestingly if I define a list:</p>
  
  <pre><code>tlist = [1,2,3,4,5]
  </code></pre>
  
  <p>and execute</p>
  
  <pre><code>print(filterval(tlist,2))
  </code></pre>
  
  <p>it still prints None, but printing tlist reveals that '2' has been removed successfully.</p>
  
  <p>What am I doing wrong?</p>