mapping = {
"N": [348.75, 360.01],
"N/": [0, 11.25],
"NNE": [11.25, 33.75],
"NE": [33.75, 56.25],
"ENE": [56.25, 78.75],
"E": [78.75, 101.25],
"ESE": [101.25, 123.75],
"SE": [123.75, 146.25],
"SSE": [146.25, 168.75],
"S": [168.75, 191.25],
"SSW": [191.25, 213.75],
"SW": [213.75, 236.25],
"WSW": [236.25, 258.75],
"W": [258.75, 281.25],
"WNW": [281.25, 303.75],
"NW": [303.75, 326.25],
"NNW": [326.25, 348.75]
}
当我打印时,订单会发生变化。
这基本上用于创建pdf并且订单已更改。如何以完全相同的顺序打印它。
P:S:这个json是硬编码的。
答案 0 :(得分:0)
事实是Python中的字典是无序的。要保留订单,您需要明确设置:
order = 'N,N/,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW'.split(',')
mapping_list = [(direction, mapping[direction]) for direction in order]
现在您的映射存储在mapping_list
内。您可以按如下方式迭代它:
for direction, coords in mapping_list:
print(direction)