标签: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)
标签:dash int style python Python标准库 pytho imp for print
原文地址:https://www.cnblogs.com/dapan-no1/p/10714283.html