0
dictionary = {(1,1):[(2,2),[(3,3),(4,4)],5]}
dictionary[(2,2)] = [(3,3),[(4,4),(5,5)],6]
dictionary[(3,3)] = [(4,4),[(5,5),(6,6)],7]
print dictionary
以上代碼給輸出:如何重新排列在Python詞典
{(3, 3): [(4, 4), [(5, 5), (6, 6)], 7], (1, 1): [(2, 2), [(3, 3), (4, 4)], 5], (2, 2): [(3, 3), [(4, 4), (5, 5)], 6]}
但是,我想要的輸出順序輸入,即提供
{(1,1):[(2,2),[(3,3),(4,4)],5],(2,2):[(3,3),[(4,4),(5,5)],6],(3,3):[(4,4),[(5,5),(6,6)],7]}
我如何重新安排詞典?
而不是試圖做到這一點,看看有序字典https://docs.python.org/2/library /collections.html#collections.OrderedDict – elelias
您是否需要訂購一般或僅在打印時訂購?當它打印時訂購 –
.. –