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
Livid
V2EX  ›  Python

关于 Python 里 tuples 和 list 的区别

  •  
  •   Livid · 2012-08-11 01:50:47 +08:00 · 7134 次点击
    这是一个创建于 4288 天前的主题,其中的信息可能已经有所发展或是发生改变。
    4 条回复    1970-01-01 08:00:00 +08:00
    tywtyw2002
        1
    tywtyw2002  
       2012-08-11 03:30:12 +08:00
    一个可以修改 一个不能修改
    Livid
        2
    Livid  
    MOD
    OP
       2012-08-11 03:54:37 +08:00
    @tywtyw2002 而且 tuples 可以作为 dict 的 key。
    beiye
        3
    beiye  
       2012-08-11 04:55:10 +08:00
    @Livid 其实就是1楼说的
    因为不可修改,才是hashable的,然后才能当作dict的key,同样set也是必须能够hashable
    比如list就不能放到set里面去
    phay
        4
    phay  
       2012-08-11 18:16:50 +08:00
    hashable和immutable有关联只是为了hash时有O(1)的效率。自定义容器,提供__hash__, __cmp__即可。。效率自己控制。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1012 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:32 · PVG 04:32 · LAX 13:32 · JFK 16:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.