Tei*_*ion 41 python dictionary
这是我的字典
propertyList = {
"id": "int",
"name": "char(40)",
"team": "int",
"realOwner": "int",
"x": "int",
"y": "int",
"description": "char(255)",
"port": "bool",
"secret": "bool",
"dead": "bool",
"nomadic": "bool",
"population": "int",
"slaves": "int",
}
Run Code Online (Sandbox Code Playgroud)
但是当我用"\n".join(myDict)打印出来时,我得到了这个
name
nomadic
dead
port
realOwner
secret
slaves
team
y
x
population
id
description
Run Code Online (Sandbox Code Playgroud)
我知道字典是无序的,但每次出现都是一样的,我不知道为什么.
您可以依赖的字典排序唯一的事情是,如果没有对字典进行修改,顺序将保持不变; 例如,在不修改字典的情况下迭代字典两次将导致相同的键序列.但是,尽管Python字典的顺序是确定性的,但它可能会受到插入顺序和删除等因素的影响,因此相同的字典最终会有不同的顺序:
>>> {1: 0, 2: 0}, {2: 0, 1: 0}
({1: 0, 2: 0}, {1: 0, 2: 0})
>>> {1: 0, 9: 0}, {9: 0, 1: 0}
({1: 0, 9: 0}, {9: 0, 1: 0})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
42700 次 |
| 最近记录: |