Python上的字典未按分配的值存储[重复项]

问题描述 投票:0回答:1

所以刚刚开始使用Python创建字典(如果有帮助的话,可以使用Spyder)...基本上制作了一个名为t的字典,但是值没有按照我分配的顺序存储

t={'first':'a','second':'b','third':'c'}
print t
for i in t :
    print t[i]

t中的值被存储为{'second':'b','third':'c','first':'a'}}并以此进行分配?这是怎么回事?

python python-2.x
1个回答
0
投票
t={'first':'a','second':'b','third':'c'}
print( t)
for i in t :
    print (t[i])

输出:

{'first': 'a', 'second': 'b', 'third': 'c'}
a
b
c

您使用有序还是无序词典?

© www.soinside.com 2019 - 2024. All rights reserved.