跳转到主要内容

不可变字典类。

项目描述

PyPI version Doc Status License PyPI - Downloads

constantdict

Python的不可变字典类,作为Python内置dict类的薄层实现。它通常比其他不可变字典实现更快。

用法

使用以下命令安装此包

$ pip install constantdict

用法示例

from constantdict import constantdict

cd = constantdict({1: 2})

# constantdicts compare equal to dicts with the same items
assert cd == {1: 2}

# constantdicts are hashable, and their hashes are cached
print(hash(cd), cd)

# Attempting to modify the constantdict raises an AttributeError
try:
    # Similar for pop(), popitem(), clear(), __ior__(), del, and setdefault()
    cd[4] = 12
except AttributeError:
    pass

请参阅文档,以及examples/目录中的示例。

参考文献

其他包

PEPs

许可证

MIT许可证。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

此版本未提供源分布文件。请参阅生成分布存档的教程

构建分布

constantdict-2024.2-py3-none-any.whl (5.8 kB 查看哈希值)

上传于 Python 3

由以下支持