码迷,mamicode.com
首页 > 编程语言 > 详细

python标准库之collections

时间:2019-04-16 00:49:00      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:dash   int   style   python   Python标准库   pytho   imp   for   print   

一.模块 collections 中的一个类—— OrderedDict 。
(字典让你能够将信息关联起来,但它们不记录你添加键 — 值对的顺序。要创建字典并记录其
中的键 — 值对的添加顺序,可使用模块 collections 中的 OrderedDict 类。 OrderedDict 实例的行为
几乎与字典相同,区别只在于记录了键 — 值对的添加顺序。)

from collections import OrderedDict
#假设age_1 到age_5 都存在(不写了)
my_dict=OrderedDict()
my_dict[age_1]="10"
my_dict[age_2]="20"
my_dict[age_3]="30"
my_dict[age_4]="40"
my_dict[age_5]="50"
for k,v in my_dict.items():
print("他们的顺序应该是:"+k+"对应"+v)

python标准库之collections

标签:dash   int   style   python   Python标准库   pytho   imp   for   print   

原文地址:https://www.cnblogs.com/dapan-no1/p/10714283.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!