首页 > 代码库 > 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)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。