Python哈希函数 [英] Python Hash Functions

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

问题描述

用python哈希层次结构(类似于文件结构)的一种好方法是什么?

What is a good way of hashing a hierarchy (similar to a file structure) in python?

我可以将整个层次结构转换为点线字符串,然后对其进行哈希处理,但是有没有更好的(或更有效的)方法来实现此目的而又不总是来回移动?

I could convert the whole hierarchy into a dotted string and then hash that, but is there a better (or more efficient) way of doing this without going back and forth all the time?

我可能想要散列的结构的一个示例是:

An example of a structure I might want to hash is:

a -> b1 -> c -> 1 -> d
a -> b2 -> c -> 2 -> d
a -> c -> 1 -> d

推荐答案

如果您可以将元组组件作为元组访问,则只需对其进行哈希处理-元组是可哈希化的.在定界字符串之间进行转换可能不会带来太多好处,但这只是一个开始.

If you have access to your hierarchy components as a tuple, just hash it - tuples are hashable. You may not gain a lot over conversion to and from a delimited string, but it's a start.

如果这没有帮助,也许您可​​以提供有关如何存储层次结构/路径信息的更多信息.

If this doesn't help, perhaps you could provide more information about how you store the hierarchy/path information.

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

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