I have a list in Python. The list has 5 elements, which can either be "None" or any other string. I want to test if each element is not "None" (that is if all the elements are set).
I've written the following code (where userInventory
is the 5-element list) :
if all(item is not None for item in userInventory):
print = "Inventory is full, you rat!"
else:
...
For example, ['None', 'Monkey', 'None', 'Jewel', 'None']
should go to the else statement, while ['None', 'None','None','None','None']
should display the message. But right now, the if statement returns true for all the lists...
NOTE The list comes from an HTML form parsed by the cgi library. The data was initially placed by Python and appear like this in HTML : <input type="hidden" name="Inventory1" value="None">
userInventory=[form.getvalue("Inventory1"),form.getvalue("Inventory2"),form.getvalu e("Inventory3"),form.getvalue("Inventory4"),form.getvalue("Inventory5")]