What is wrong with my code to remove duplicates from Linked List?
<p>New to Python and my code is passing all test cases other than input 1-->0, which it returns nothing instead of 1->0. does this have something to do with the value of None?</p>

<pre><code>def RemoveDuplicates(head):
    if head == None or head.next == None:
        return 
    else:
        temp = head
        while(temp.next != None):
            if temp.data == temp.next.data:
                temp.next = temp.next.next
            else:
                temp = temp.next
        return head
</code></pre>

<p>We can't see the class of head and what operations it has defined, is the <code>__eq__</code> magic function defined on that class?</p>

<p>Is it possible that <code>head.next == None</code> evaluates to <code>head.next.data == None</code> for the class?  In which case <code>0 == None</code> evaluates to True.</p>

<p>As others have mentioned this is fixed by using <code>head.next is None</code></p>

<p>I suspect you're supposed to <code>return head</code> in the first case regardless, but it doesn't seem like it should be triggering in this case unless the evaluations I mention above are happening. </p>

python