python - OrderedDict 的设置、获取和 popitem 性能

标签 python python-2.7 dictionary ordereddictionary

<分区>

OrderedDict需要维护一个项目的插入顺序,我想知道get的性能是什么/set/popitem在 Python 2.7 中?到目前为止还没有找到任何官方文件。 我猜 getO(1) , setO(logN)popitemO(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 - 将列 append 到新数据框

python - IDLE 因 url 读取而崩溃

Python 2.7 : 'ascii' codec can't encode character u'\xe9' error while writing in file

python - 有效连接 DataFrame 索引的两个标签

python - 如何在Python爬虫中访问多页面表单的发布数据

python - 解析字典的最快 pythonic 方式,其中值是字节字符串化的 json 对象

Python。将 2 个列表转换为一个字典对象

ios - 从 swift 向 NSMutableArray 添加字典