indexing a dictionary with key hash values
<p>I am currently going through learn python the hard way, and i find my self stuck on this dictionary exercise: <a href="http://learnpythonthehardway.org/book/ex39.html" rel="nofollow">http://learnpythonthehardway.org/book/ex39.html</a></p>

<p>What gives me problems is the following code:</p>

<pre><code>def hash_key(aMap, key):
    """Given a key this will create a number and then convert it to
    an index for the aMap's buckets."""
    return hash(key) % len(aMap)
</code></pre>

<p>How can i be sure that i wont get duplicate values from the hash_key function? Since modulo is being used, what prevents hash() from returning values such that after modulo is used on them they return the same hash_key.</p>

<p>Ex. <code>len(aMap)=10</code>, <code>hash(key1) = 20</code>, <code>hash(key2) = 30</code>, therefore <code>hash_key</code> for both dict keys is 0, even though they are obviously not equal.</p>

<p>I'm having trouble grasping the concepts behind hashing, so if you have any reading material suitable for my skill level, please share. I'm not afraid to work hard. </p>

<p>Thank you for your help.</p>