如同这个数据结构的名称所说的那样,它记录了每个键值对添加的顺序. ? 1 2 3 4 5 6 d = OrderedDict() d['a'] = 1 d['b'] = 10 d['c'] = 8 for letter in d: print letter 输出: ? 1 2 3 a b c 如果初始化的时候同时传入多个参数,它们的顺序是随机的,不会按照位置顺序存储. ? 1 2 >>> d = OrderedDict(a=1, b=2, c=3) OrderedDict([('a'…
基本数据类型补充: set 是一个无序且不重复的元素集合 class set(object): """ set() -> new empty set object set(iterable) -> new set object Build an unordered collection of unique elements. """ def add(self, *args, **kwargs): # real signature un…
collections模块基本介绍 collections在通用的容器dict,list,set和tuple之上提供了几个可选的数据类型 namedtuple() factory function for creating tuple subclasses with named fields deque list-like container with fast appends and pops on either end ChainMap dict-like class for creatin…
""" The main QuerySet implementation. This provides the public API for the ORM. """ import copy import sys import warnings from collections import OrderedDict, deque from django.conf import settings from django.core import ex…