V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
sudo987
V2EX  ›  Python

hash()出来的结果是哈希表的索引,如何用这个索引直接取值

  •  
  •   sudo987 · 2016-07-11 23:54:58 +08:00 via iPhone · 2392 次点击
    这是一个创建于 2847 天前的主题,其中的信息可能已经有所发展或是发生改变。
    >>> d = {'name':'xx'}
    >>> hash('name')
    -4166578487145698715

    那么-4166578487145698715 就是索引,怎么利用这个数取得‘ xx ’呢?
    3 条回复    2016-07-12 10:25:20 +08:00
    menc
        1
    menc  
       2016-07-12 01:06:53 +08:00   ❤️ 2
    对于一个 hash table , hash 出来的结果不一定是元素存储的索引,因为 hash 算法很可能存在 collision ,所以你的前提“ hash()出来的结果是哈希表的索引”,是错误的
    20015jjw
        2
    20015jjw  
       2016-07-12 02:37:06 +08:00
    hashtable 的原理建议 lz 看一下
    wander2008
        3
    wander2008  
       2016-07-12 10:25:20 +08:00 via iPhone
    hashtable 的索引如果两个 hash 值碰撞了。你怎么办?所以这个结论不太准确。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5448 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 08:06 · PVG 16:06 · LAX 01:06 · JFK 04:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.