Skip to main content

iibags

English | 中文

带显式算术的计数多重集合。

安装

pip install iibags

用法

from iibags import MultiBag

bag = MultiBag(["a", "b", "a"])
bag.count("a")          # 2
bag.count("zzz")        # 0,且没有创建键
bag.total()             # 3
bag.unique()            # 2
bag.most_common(1)      # [('a', 2)]

bag.discard("a", 5)     # 归零并删除键
"a" in bag              # False

说明

与 Counter 的差别:读一个不存在的键不会创建它;扣减超额时归零并删除键,不留负数;n_count 传负数直接抛 ValueError——负计数是「库存怎么变成 -3」的常见根源。

许可证

MIT


English

A counting multiset with explicit arithmetic.

Install

pip install iibags

Usage

from iibags import MultiBag

bag = MultiBag(["a", "b", "a"])
bag.count("a")          # 2
bag.count("zzz")        # 0,且没有创建键
bag.total()             # 3
bag.unique()            # 2
bag.most_common(1)      # [('a', 2)]

bag.discard("a", 5)     # 归零并删除键
"a" in bag              # False

Notes

Unlike Counter: reading a missing key does not create it, over-subtracting clamps to zero and drops the key, and a negative n_count raises ValueError. Negative counts are the usual source of "why is my inventory -3" bugs.

License

MIT

Metadata

Release files for iibags 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iibags 0.0.3
File Size Uploaded Provenance Actions
iibags-0.0.3.tar.gz 3.6 kB Without provenance Details for iibags-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for iibags 0.0.3
File Interpreter ABI Platform Actions
iibags-0.0.3-py3-none-any.whl Python 3 none any Details for iibags-0.0.3-py3-none-any.whl

Total release size: 7.5 kB

Release files / iibags-0.0.3.tar.gz

Download URL iibags-0.0.3.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
779c5aa2aa6bc43dff456644c5003a3d13b01c7b23436c977579ac6f79c6ba68
BLAKE2b-256 checksum
How to use checksums
7a96b370f7927a23c5337bbb1760b3044000dfd3ceee5db678a1f51d54e6d271
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release files / iibags-0.0.3-py3-none-any.whl

Download URL iibags-0.0.3-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d14a5a502c525b1f062f11a6b96f6717661ffef8c4a8b37268c58a58e28c191c
BLAKE2b-256 checksum
How to use checksums
cdb93f2be1ee3049bb74885be11e8a61a9bbc7da788d57b5442fc6d88f2e3829
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Security for iibags 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page