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

python 有没类似 php 一样的关联数组写法

  •  
  •   617450941 · 2015-11-29 19:12:42 +08:00 · 3221 次点击
    这是一个创建于 3076 天前的主题,其中的信息可能已经有所发展或是发生改变。
    貌似 python 的 list 只有索引方式访问 list 内的元素 不能对元素进行定义名称
    12 条回复    2015-12-05 08:40:47 +08:00
    pynix
        1
    pynix  
       2015-11-29 19:22:55 +08:00
    字典是吃干饭的吗?
    Slienc7
        2
    Slienc7  
       2015-11-29 19:23:46 +08:00
    dict
    saxon
        3
    saxon  
       2015-11-29 19:23:46 +08:00
    @pynix 楼上的头像是 Ruby 么。。。
    knktc
        4
    knktc  
       2015-11-29 19:27:20 +08:00
    你说的是有序字典? collections.OrderedDict ?
    pynix
        5
    pynix  
       2015-11-29 19:58:09 +08:00
    @saxon 是的,自己做的, svg 已丢失。。。。
    irgil
        6
    irgil  
       2015-11-29 20:27:10 +08:00
    php 中的关联数组实际上就是一个简化版的 map ,所以用 python 中的 dict 就可以
    matthewz
        7
    matthewz  
       2015-11-29 20:49:45 +08:00
    或者 namedtuple 其实就是个简单的 class
    LINAICAI
        8
    LINAICAI  
       2015-11-29 21:18:28 +08:00
    楼主认真看过 php 和 python 的语法?
    Changxu
        9
    Changxu  
       2015-11-29 21:53:23 +08:00
    LZ 你真的自以为学过 Python ?
    ChiChou
        10
    ChiChou  
       2015-11-29 22:05:16 +08:00
    what = {"is": "this"}
    XianZaiZhuCe
        11
    XianZaiZhuCe  
       2015-12-01 09:31:37 +08:00
    @Changxu 请尽量让自己的回复能够对别人有帮助
    617450941
        12
    617450941  
    OP
       2015-12-05 08:40:47 +08:00 via Android
    @LINAICAI 就是不知道才问呀
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2072 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 10:46 · PVG 18:46 · LAX 03:46 · JFK 06:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.