如何散列列表? [英] How to hash lists?

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

问题描述

列表不可散列。然而,我是实施LSH ,我正在寻求散列函数,它将对应于k个桶中的正整数列表(在[1,29.000]中)。列表的数量是D,其中D> k(我认为)和D = 40.000,其中k还不知道(开放给建议)。




示例(D = 4,k = 2):

  118 | 27 | 1002 | 225 
128 | 85 | 2000 | 8700
512 | 88 | 2500 | 10000 $ b $ 600 | 97 | 6500 | 24000
800 | 99 | 7024 | 25874

第一列应作为散列函数的输入,并返回一个存储桶的编号。




令我感到困惑的是,我们不寻求函数来散列数字,而是寻找列,即列表

有什么想法吗?

我正在使用 python 如果那么重要

解决方案

>在[4]中:hash(l)
TypeError:不可用类型:'list'
$ b $ hash(元组(l))%k#29000
输出[5]: 70846


Lists are not hashable. However, I am implementing LSH and I am seeking for a hash function that will correspond a list of positive integers (in [1, 29.000]) to k buckets. The number of lists is D, where D > k (I think) and D = 40.000, where k is not yet known (open to suggestions).


Example (D = 4, k = 2):

118 | 27 | 1002 | 225
128 | 85 | 2000 | 8700
512 | 88 | 2500 | 10000
600 | 97 | 6500 | 24000
800 | 99 | 7024 | 25874

The first column should be given as input to the hash function and return the number of a bucket.


What confuses me is that we do not seek for a function to hash a number, but a column, i.e. a list of positive integers.

Any ideas please?

I am using if that matters

解决方案

You can just convert it in a hashable type before :

In [4]: hash(l)
TypeError: unhashable type: 'list'

hash(tuple(l)) % k  # 29000
Out[5]: 70846

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

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