在Python散列阵列 [英] Hashing arrays in Python

查看:176
本文介绍了在Python散列阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能哈希列表

例如,我知道,元组的哈希值是可能的:

For example, I know that hashes of tuples are possible:

>>> hash((1,2,3,4,5,6))
-319527650

但有可能哈希一个列表

>>> hash([1,2,3,4,5,6])
hash_value

可能的解决方案:

非常深入的解释,以列表的哈希,这里

推荐答案

试试吧:

>>> hash((1,2,3))
2528502973977326415
>>> hash([1,2,3])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
>>> hash(frozenset((1,2,3)))
-7699079583225461316
>>> hash(set((1,2,3)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'set'

所以,你可以得到 元组 frozenset 既然是不可变的,你不能对列表做设置,因为它们是可变的。

So you can get hash of tuple and frozenset since the are immutable, and you can't do it for list and set because they are mutable.

这篇关于在Python散列阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆