`object in list` behaves different from `object in dict`?
<p>I've got an iterator with some objects in it and I wanted to create a collection of uniqueUsers in which I only list every user once. So playing around a bit I tried it with both a list and a dict:</p>

<pre><code>&gt;&gt;&gt; for m in ms: print m.to_user  # let's first look what's inside ms
...
Pete Kramer
Pete Kramer
Pete Kramer
&gt;&gt;&gt; 
&gt;&gt;&gt; uniqueUsers = []  # Create an empty list
&gt;&gt;&gt; for m in ms:
...     if m.to_user not in uniqueUsers:
...         uniqueUsers.append(m.to_user)
...
&gt;&gt;&gt; uniqueUsers
[Pete Kramer]  # This is what I would expect
&gt;&gt;&gt; 
&gt;&gt;&gt; uniqueUsers = {}  # Now let's create a dict
&gt;&gt;&gt; for m in ms:
...     if m.to_user not in uniqueUsers:
...         uniqueUsers[m.to_user] = 1
...
&gt;&gt;&gt; uniqueUsers
{Pete Kramer: 1, Pete Kramer: 1, Pete Kramer: 1}
</code></pre>

<p>So I tested it by converting the dict to a list when doing the if statement, and that works as I would expect it to:</p>

<pre><code>&gt;&gt;&gt; uniqueUsers = {}
&gt;&gt;&gt; for m in ms:
...     if m.to_user not in list(uniqueUsers):
...         uniqueUsers[m.to_user] = 1
...
&gt;&gt;&gt; uniqueUsers
{Pete Kramer: 1}
</code></pre>

<p>and I can get a similar result by testing against <code>uniqueUsers.keys()</code>. </p>

<p>The thing is that I don't understand why this difference occurs. I always thought that if you do <code>if object in dict</code>, it simply creates a list of the dicts keys and tests agains that, but that's obviously not the case.</p>

<p>Can anybody explain how <code>object in dict</code> internally works and why it doesn't behave similar to <code>object in list</code> (as I would expect it to)?</p>