内置 Python hash() 函数 [英] Built in Python hash() function

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

问题描述

Windows XP,Python 2.5:

Windows XP, Python 2.5:

hash('http://stackoverflow.com') Result: 1934711907

Google 应用引擎(http://shell.appspot.com/):

Google App Engine (http://shell.appspot.com/):

hash('http://stackoverflow.com') Result: -5768830964305142685

这是为什么?我怎样才能拥有一个散列函数,它可以在不同平台(Windows、Linux、Mac)上给我相同的结果?

Why is that? How can I have a hash function that will give me same results across different platforms (Windows, Linux, Mac)?

推荐答案

使用 hashlib 作为 hash() 旨在用于:

在字典查找过程中快速比较字典键

quickly compare dictionary keys during a dictionary lookup

因此不保证它在 Python 实现中是相同的.

and therefore does not guarantee that it will be the same across Python implementations.

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

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