First - and important thing:
while p is not None and p.data is not value:
You comparison p.data is not value
is something different from p.data != value
- and I guest that you wanted the second.
is
means the same object, while ==
means the same value (of optionally different objects). For small integers - as in your test - Python uses the same predefined object but for e. g. 500500
or -50-50
it is not true - try in your interpreter
500 + 1 is 501
and you will obtain False
.
Second, you need not compare to None
(or to 0
, or to ''
, etc.) as its boolean value is False. So the same command - in this case the correct one - may be
while not p and p.data != value:
(and similarly for your other commands).