Removing item from list causes the list to become NoneType

Solution 1:

remove doesn't return anything. It modifies the existing list in-place. No assignment needed.

Replace

var = ['p', 's', 'c', 'x', 'd'].remove('d') 

with

var = ['p', 's', 'c', 'x', 'd']
var.remove('d') 

Now var will have a value of ['p', 's', 'c', 'x'].

Solution 2:

remove mutates the list in-place, and returns None. You have to put it in a variable, and then change that:

>>> var = ['p', 's', 'c', 'x', 'd']
>>> var.remove('d')   # Notice how it doesn't return anything.
>>> var
['p', 's', 'c', 'x']