python基础一 ------"有序"的字典

"有序"字典:按照写入字典的先后顺序排序的字典(比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,i
10 
11 print(type(d))
12 print(d)
13 print("-----------------------") 
14 print(type(f))
15 print(f)

运行截图:

 

posted @ 2017-05-10 19:37  若鸟  阅读(169)  评论(0编辑  收藏  举报