Meg*_*ron 0 python dictionary python-3.x
有谁知道python3使用什么样的哈希函数?有没有办法重新实现函数接受列表作为键?
Mar*_*ers 5
看hash()功能 ; 对象类型实现__hash__钩子函数.
hash()
__hash__
不,你不能让它接受list,但是list可以使子类起作用.请注意,不保持密钥的哈希和相等测试稳定会破坏您的字典.
list
但是,最好将tuples存储为键.将列表转换为元组非常简单:
tuple
my_dictionary[tuple(my_list)] = my_value
归档时间:
12 年,1 月 前
查看次数:
186 次
最近记录: