python之collections之有序字典(OrderedDict)
生活随笔
收集整理的這篇文章主要介紹了
python之collections之有序字典(OrderedDict)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一、定義
OrderedDict是對字典的補充,它記住了字典元素的添加順序。
eg: 二、OrderedDict相關(guān)方法
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
設(shè)置默認值
"""
pass
def update(self, *args, **kwargs): # real signature unknown
pass
def values(self, *args, **kwargs): # real signature unknown
pass
OrderedDict是對字典的補充,它記住了字典元素的添加順序。
eg: 二、OrderedDict相關(guān)方法
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
設(shè)置默認值
"""
pass
def update(self, *args, **kwargs): # real signature unknown
pass
def values(self, *args, **kwargs): # real signature unknown
pass
轉(zhuǎn)載于:https://www.cnblogs.com/baotouzhangce/p/6182366.html
總結(jié)
以上是生活随笔為你收集整理的python之collections之有序字典(OrderedDict)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 单词本.
- 下一篇: Python网络编程之TCP服务器客户端