python中collections.OrderedDict()

import collections #from collections import OrderededDict
my_orderDict=collections.OrderedDict(house=None,name='lily',age=18,degree="Dr.",b=1,a=2,)
for key,value in my_orderDict.items():
    print(key,value)
因为字典输出时经常时随机无序的,所以没法保证按照您输入字典的顺序来输出,当用了collections.OrderedDic(),
可以按照字典内读取/输入的先后顺序来输出。这就是collections.OrderedDic()函数的作用。

  

原文地址:https://www.cnblogs.com/Li-JT/p/15181819.html