python的Dictionary类型是无序的,所以当我们想要字典安装插入的顺序输出时,我们可以使用collections的OrderedDict来实现
示例:
from collections import OrderedDict
favorite_languages = OrderedDict()
favorite_languages['jen'] = 'python'
favorite_languages['sarah'] = 'c'
favorite_languages['edward'] = 'ruby'
favorite_languages['phil'] = 'python'
for name,language in favorite_languages.items():
print(name.title() + "'s favorite language is " + language.title() + ".")
输出结果