OrderedDict是一个字典子类,它记住其内容的添加顺序,它在Python库的collections模块中定义。OrderDict记住字典中键值对的添加顺序
>>> from collections import OrderedDict >>> od=OrderedDict(d.items()) >>> od OrderedDict([('banana', 3), ('apple', 4), ('pear', 1), ('orange', 2)]) >>> t=od.popitem() >>> t ('orange', 2)