<分区>
自 OrderedDict
需要维护一个项目的插入顺序,我想知道get
的性能是什么/set
/popitem
在 Python 2.7 中?到目前为止还没有找到任何官方文件。
我猜 get
是O(1)
, set
是O(logN)
和 popitem
是O(1)
.
这是 collection.OrdereDict
documentation .
<分区>
自 OrderedDict
需要维护一个项目的插入顺序,我想知道get
的性能是什么/set
/popitem
在 Python 2.7 中?到目前为止还没有找到任何官方文件。
我猜 get
是O(1)
, set
是O(logN)
和 popitem
是O(1)
.
这是 collection.OrdereDict
documentation .
最佳答案
我刚刚检查了 Implementation of python Orderedlist object from Python mercurial repository .在 odictobject.c 文件的注释中,他们指出:Python 的 OrderedDict 的一个不变性是它保留了 dict 方法的时间复杂度,尤其是 O(1) 操作。
关于python - OrderedDict 的设置、获取和 popitem 性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38558288/
相关文章:
ubuntu 中 crontab 中的 Python3 脚本
python - 应用引擎 : Is there a good general-purpose tool for caching datastore objects?
Python 2.7 : 'ascii' codec can't encode character u'\xe9' error while writing in file
python - 有效连接 DataFrame 索引的两个标签
python - 如何在Python爬虫中访问多页面表单的发布数据