python ordered dictionary feature in collections namespaces

>>> import collections
>>> a=OrderedDict()

Traceback (most recent call last):
  File "<pyshell#16>", line 1, in <module>
    a=OrderedDict()
NameError: name 'OrderedDict' is not defined
>>> a=collections.OrderedDict()
>>> a["k"]=1
>>> a[0]=2
>>> a
OrderedDict([('k', 1), (0, 2)])
>>> for k,v in a.iteritems():
    print k,v

   
k 1
0 2
>>>

你可能感兴趣的:(Collections)