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

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

问题描述

Windows XP,Python 2.5:

  hash('http://stackoverflow.com')结果:1934711907 

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

  hash('http://为什么会这样呢?)为什么会这样呢?为什么会这样???????????b 



我怎样才能有一个散列函数,它会给我不同的平台(Windows,Linux,Mac)相同的结果? #module-hashlibrel =noreferrer> hashlib 作为 hash() 被设计用于


快速比较字典在字典查找中使用键


,因此不能保证在Python实现中它是相同的。


Windows XP, Python 2.5:

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

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

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

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

解决方案

Use hashlib as hash() was designed to be used to:

quickly compare dictionary keys during a dictionary lookup

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

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

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