"有序"字典:按照写入字典的先后顺序排序的字典(比list优点是按键查询)
1 #-*-coding:utf-8 -*- 2 #"有序"字典:按照写入字典的先后顺序排序的字典(比list优点是按键查询) 3 from collections import OrderedDict 4 d = OrderedDict() 5 f = {} 6 l = [i for i in range(10)] 7 for x in "ABCDEFGHIJ": 8 i = l.pop() 9 d[x],f[x] = i,i10 11 print(type(d))12 print(d)13 print("-----------------------") 14 print(type(f))15 print(f)
运行截图: