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

Mr.*_*o73 2 python dictionary list python-2.7

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

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', '150': 'potato_starch'}
Run Code Online (Sandbox Code Playgroud)

为什么通过颠倒列表,字典'c'失去两对'成分:数量'?
我注意到最多6对都没问题.
我为不完整的解释道歉,但我不知道如何向我解释这是一个异常.
感谢谁愿意帮助我理解.

Mos*_*oye 5

反转参数的顺序意味着先前的字典值现在将优先作为键.

更重要的是,先前的字典具有重复值(例如300).但是,一旦你交换了参数的顺序并且它们成为键,只有其中一个值使它成为新dict的键; 字典不允许重复键.