Python字典是无序,可更改和索引的集合。没有重复的成员。但是当我运行下面的代码时,我惊讶地看到错误的输出(有序元组),它应该是无序的。代码有什么问题?
my_dict = {}
my_dict['a'] = 1
my_dict['b'] = 2
my_dict['c'] = 3
my_dict['d'] = 4
my_dict['e'] = 5
my_dict['f'] = 6
my_dict['g'] = 7
my_dict['h'] = 8
my_dict['i'] = 9
for k, v in my_dict.items():
print(k, v)
答案 0 :(得分:3)
在CPython 3.6和(任何)Python 3.7中,字典remember their key insertion order以及对console.log node_modules/react-testing-library/dist/index.js:58
<body>
<div>
<div
class="ui card"
>
<div
class="ui image"
>
<div
class="ui inverted dimmer"
data-testid="combo-item-dimmer"
>
<div
class="content"
>
<span
style="margin-top: auto; color: black;"
>
Out of stock
</span>
</div>
</div>
<img
src="combo-xoi.jpg"
/>
</div>
</div>
</div>
</body>
,dict.keys
和dict.values
的调用将反映该顺序。
此外,在较早的实现中打印时,您可以获取的所有任意顺序的集合中都包含“按巧合顺序排列”。 :)