from collections import OrderedDict
import pprint
menu = {"about" : "about", "login" : "login", 'signup': "signup"}
menu = OrderedDict(menu)
pprint.pprint(menu.items())
import sys
sys.exit()
The output is:
[('about', 'about'), ('signup', 'signup'), ('login', 'login')]
So, the order is not preserved even with the use of OrderedDict
. I know the dictionaries don't preserve the initial order by default, and all those things. But I want to learn why the OrderedDict
is not working.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…