小编Mr.*_*o73的帖子

如果我颠倒了zip列表的顺序,为什么我会得到两个不同的词典

我对以下代码感到有点困惑:

Python 2.7.13 (default, Jan 19 2017, 14:48:08)
[GCC 6.3.0 20170118] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> list_a = ['300', '300', '200', '150', '150', '120', '1']

>>> list_b = ['butter', 'sugar', 'yolks', 'flour', 'potato_starch', 'egg_whites', 'lemon_zest']

>>> c = dict(zip(list_b, list_a))

>>> print c
>>>{'butter': '300', 'lemon_zest': '1', 'flour': '150', 'egg_whites': '120', 'sugar': '300', 'yolks': '200', 'potato_starch': '150'}

>>> c = dict(zip(list_a, list_b))

>>> print c
>>>{'300': 'sugar', '200': 'yolks', '1': 'lemon_zest', '120': 'egg_whites', …
Run Code Online (Sandbox Code Playgroud)

python dictionary list python-2.7

2
推荐指数
1
解决办法
56
查看次数

标签 统计

dictionary ×1

list ×1

python ×1

python-2.7 ×1