擅长:python、mysql、java
<p>我也尝试在哈希图中建立第三层,我做了,这就是我的代码实现的。在</p>
<p><a href="http://i.stack.imgur.com/aZxiQ.png" rel="nofollow">Because type 'list' is not hashable,so let's keep the 'key' type still 'string',and made 'value' type list.</a>
附言:我是一名来自中国的学生,请原谅我奇怪的英语表达。只是想帮忙!在</p>
<p>这是我代码的关键部分:</p>
<pre><code>def set(aMap, key, value):
'''Sets the key to the value, replacing an existing value.'''
bucket = get_bucket(aMap, key)
i, k, vlist = get_slot(aMap, key)
if i >= 0:
# the key exists, append it
vlist.append(value)
else:
# the key does not, append to creat it
bucket.append((key,[value]))
# attention! the key is string and value becomes list,which is the 3rd layer of bucket.
</code></pre>
<p>其他功能也需要相应的改变。在</p>
<p>注意ex39中的这个语句_测试.py公司名称:</p>
^{pr2}$
<p>在上面的语句中,当我们调用hashmap.get函数时,它将返回一个值,但该值的类型应为list,并且它将成为hashmap.get当我们再次调用它的时候函数!
如果你没有注意到它,计算机会把这个键散列进去,它的类型是list,这将导致一个不可修复的错误。在</p>
<p>这就是我在hashmap.py公司名称:</p>
^{3}$