Python的collections模块中的OrderedDict有序字典
2017-07-12 22:18
826 查看
排序实现:
import collections
常规dict并不跟踪插入顺序,迭代处理会根据键在散列表中存储的顺序来生成值。在OrderDict中则相反,它会记住元素插入的顺序,并在创建迭代器时使用这个顺序。
import collections
def numOfRepeat(numOfList,numOfSet): d = collections.OrderedDict() for i in numOfSet: count = 0 for j in numOfList: if i == j: count += 1 print "%d 对应的个数:%d" % (i, count) d[i] = count # s=sorted(d.items(),key=lambda x:x[0]) return d # s=list(s) # for key, value in d.items(): # print key, value笔记记录:
常规dict并不跟踪插入顺序,迭代处理会根据键在散列表中存储的顺序来生成值。在OrderDict中则相反,它会记住元素插入的顺序,并在创建迭代器时使用这个顺序。
相关文章推荐
- Python的collections模块中的OrderedDict有序字典
- python模块介绍- collections(5)-OrderedDict 有序字典
- Python的collections模块中的OrderedDict有序字典
- Python的collections模块中的OrderedDict有序字典
- python 2-6 如何让字典保持有序collections.OrderedDict
- python模块简介之有序字典(OrderedDict)
- python模块简介之有序字典(OrderedDict)
- 【python】collections模块(有序字典,计数器,双向队列)
- python 有序字典OrderedDict
- collections系列之OrderedDict【有序字典】与DefaultDict【默认字典】
- Python学习笔记(三十三)常用内置模块(2)collections_namedtuple_deque_defaultdict_OrderedDict_Counter
- Python3 有序字典—OrderedDict()
- python的collection系列-有序字典(OrderedDict)
- python中的有序字典OrderedDict
- day3 collections(counter(对字典的加工) 有序字典(orderedDict)默认字典(defaultdict))可命名元组(namedtuple)
- Python collections模块
- 使用Python的内建模块collections的教程
- OrderedDict 有序字典以及读取json串时如何保持原有顺序
- python模块 - collections模块
- Python 中的collections 模块