【问题标题】:What is a better way to remove key from dict in Python 3.4? [duplicate]在 Python 3.4 中从 dict 中删除密钥的更好方法是什么? [复制]
【发布时间】:2015-07-08 07:04:24
【问题描述】:

我找到了两种方法:

del dict[key]

dict.pop(key)

哪个更好,为什么,或者还有更多?

【问题讨论】:

标签: python dictionary


【解决方案1】:

del 通常比 pop() 快。

看看这个讨论Best way to remove an item from a Python dictionary?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-06
    • 2017-12-21
    • 2017-11-10
    • 1970-01-01
    • 2015-04-12
    • 2019-03-02
    • 2018-08-16
    • 1970-01-01
    相关资源
    最近更新 更多