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

[小白提问] 关于 py 字典

  •  
  •   victsdo2005 · 2018-01-04 23:47:06 +08:00 · 2318 次点击
    这是一个创建于 2275 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最近在自学 py 字典知识的时候有个疑问,
    打个比方:
    area = {
    "asia":{
    "China":{
    "beijing":["chaoyang","tiantongyuan"],
    }
    }
    }
    最后"beijing"的 value 用的是[ ]而不是{ },有啥不同。。。
    是不是可以随便混用。。。
    7 条回复    2018-01-05 09:58:12 +08:00
    wzwwzw
        1
    wzwwzw  
       2018-01-04 23:49:10 +08:00
    [] 是 list 的吧。
    beyondorient
        2
    beyondorient  
       2018-01-04 23:51:20 +08:00 via Android
    key:value
    最内一层 value 是一个 list
    其它各层 value 都是 dict
    aristotll
        3
    aristotll  
       2018-01-04 23:54:52 +08:00
    一个是 set 一个是 list
    yexiaoxing
        4
    yexiaoxing  
       2018-01-05 07:29:37 +08:00 via iPhone
    这是一个嵌套的 dict,最后一层是个 list。dict 是一个 key-value 对。
    还是先学一下 Python 里基本的数据结构吧。
    frostming
        5
    frostming  
       2018-01-05 09:14:42 +08:00
    dict = { key1: value1, key2: value2,...}
    list = [item1, item2, ... ]
    一个是 dict, 一个是 list
    congminghaoxue92
        6
    congminghaoxue92  
       2018-01-05 09:24:21 +08:00
    ```
    In [1]: s={'a','b'}

    In [2]: type(s)
    Out[2]: set

    In [3]: d={'a':1,'b':2}

    In [4]: type(d)
    Out[4]: dict

    In [5]: l=['a','b']

    In [6]: type(l)
    Out[6]: list
    ```
    三都区别,自己试试就清楚了。
    2018
        7
    2018  
       2018-01-05 09:58:12 +08:00
    []这是列表,是有序的!和字典最大的区别!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5932 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 02:36 · PVG 10:36 · LAX 19:36 · JFK 22:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.