首页 > 代码库 > python之collections之有序字典(OrderedDict)

python之collections之有序字典(OrderedDict)

一、定义
OrderedDict是对字典的补充,它记住了字典元素的添加顺序。
eg:

技术分享

技术分享

二、OrderedDict相关方法
def clear(self): # real signature unknown; restored from __doc__
"""
    od.clear() -> None. Remove all items from od.
    清除有序字典中的元素
  """
pass
eg:

技术分享

技术分享

 


def copy(self): # real signature unknown; restored from __doc__
"""
    od.copy() -> a shallow copy of od
    有序字典的浅拷贝
  """
pass



def items(self, *args, **kwargs): # real signature unknown
取有序字典的元素
   pass

def keys(self, *args, **kwargs): # real signature unknown
  取key
pass

def move_to_end(self, *args, **kwargs): # real signature unknown
"""
Move an existing element to the end (or beginning if last==False).

Raises KeyError if the element does not exist.
When last=True, acts like a fast version of self[key]=self.pop(key).
  把指定的元素放到尾部
"""
pass
eg:

技术分享

技术分享

 


def pop(self, k, d=None): # real signature unknown; restored from __doc__
"""
od.pop(k[,d]) -> v, remove specified key and return the corresponding
value. If key is not found, d is returned if given, otherwise KeyError
is raised.
  弹出指定的key
"""
pass
eg:

技术分享

技术分享

 



def popitem(self): # real signature unknown; restored from __doc__
"""
od.popitem() -> (k, v), return and remove a (key, value) pair.
Pairs are returned in LIFO order if last is true or FIFO order if false.
  从尾部开始弹出
"""
pass
eg:

技术分享

技术分享

 


def setdefault(self, k, d=None): # real signature unknown; restored from __doc__
"""
    od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od
    设置默认值
  """
pass

def update(self, *args, **kwargs): # real signature unknown
pass

def values(self, *args, **kwargs): # real signature unknown
pass

python之collections之有序字典(OrderedDict)