推荐学习书目
› 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 · Jul 11, 2016 via iPhone · 3332 views
    This topic created in 3731 days ago, the information mentioned may be changed or developed.
    >>> d = {'name':'xx'}
    >>> hash('name')
    -4166578487145698715

    那么-4166578487145698715 就是索引,怎么利用这个数取得‘ xx ’呢?
    3 replies  •  2016-07-12 10:25:20 +08:00
    menc
        1
    menc  
       Jul 12, 2016   ❤️ 2
    对于一个 hash table , hash 出来的结果不一定是元素存储的索引,因为 hash 算法很可能存在 collision ,所以你的前提“ hash()出来的结果是哈希表的索引”,是错误的
    20015jjw
        2
    20015jjw  
       Jul 12, 2016
    hashtable 的原理建议 lz 看一下
    wander2008
        3
    wander2008  
       Jul 12, 2016 via iPhone
    hashtable 的索引如果两个 hash 值碰撞了。你怎么办?所以这个结论不太准确。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2694 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 14:53 · PVG 22:53 · LAX 07:53 · JFK 10:53
    ♥ Do have faith in what you're doing.