python OrderedDict

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() + ".")

输出结果

python OrderedDict

上一篇:《SpringBoot揭秘:快速构建微服务体系》—第1章1.4节微服务会带来哪些挑战


下一篇:tpcc-mysql的使用