--- id: multiset version: "3.2.0" license: MIT license_treatment: permissive maintenance: dormant --- # multiset — An implementation of a multiset. License: permissive · Maintenance: dormant · Downloads: 453.1K/mo ## What it is and what it does Multiset is a data structure that extends Python's built-in set to allow elements to appear multiple times. Like a set, it requires elements to be hashable and supports the same operations—membership tests, union, intersection, symmetric difference—but tracks how many times each element occurs. The package provides both a mutable Multiset class and an immutable FrozenMultiset (similar to frozenset) that is also hashable. Unlike collections.Counter from the standard library, multiset enforces proper set semantics: it only allows positive counts, automatically removes elements with zero multiplicity, and supports all standard set operations without treating the collection as a frequency counter. The implementation uses a dictionary internally to map elements to their counts, making it suitable for algorithms that need set operations on collections with duplicates. Use it for: - Counting occurrences of hashable items while performing set operations like union or intersection - Implementing algorithms that require multiset semantics (e.g., graph theory, combinatorics) where duplicate membership matters - Using multisets as dictionary keys or in sets by wrapping them in FrozenMultiset for immutability and hashability - Comparing collections where element frequency and set relationships both matter (e.g., checking if one multiset is a sub-multiset of another) - Replacing ad-hoc Counter-based logic when you need proper set operations rather than frequency counting ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides a mutable and immutable multiset data structure that extends Python's set semantics to allow duplicate elements, supporting set operations like union, intersection, and difference. Yes, if you need set operations on collections with duplicates. The package is stable, has zero dependencies, and installs easily. However, maintenance is dormant (last release 717 days ago), so consider whether you need active support or can rely on a mature, unchanging implementation. For simple frequency counting, collections.Counter may be sufficient; reach for multiset when you specifically need set semantics with duplicates. ## Install pip install multiset uv add multiset poetry add multiset ## Installing multiset Before you install: Low friction: pure Python wheel with no runtime dependencies. Maintenance is dormant—last release was 717 days ago—but the repository is not archived and the package is marked Production/Stable with support for current Python versions (3.8 through 3.12). License in practice: MIT license (permissive) imposes no restrictions on use, modification, or redistribution in proprietary or open-source projects. Quickstart: from multiset import Multiset, FrozenMultiset set1 = Multiset('aab') set2 = Multiset('abc') result = sorted(set1 | set2) # ['a', 'a', 'b', 'c'] frozen = FrozenMultiset('abc') hash(frozen) # hashable Requires Python 3.8 or later. Verify before relying: - Performance characteristics compared to collections.Counter or repeated set operations for large datasets - Whether the API is fully stable or if breaking changes are possible despite dormant maintenance status ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: dormant - Downloads: 453.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags multiset data structure, set with duplicates, hashable collection duplicates, union intersection multiset, frozenset alternative, counter-like set operations, mutable multiset, data-structures, set-operations [View on SkillFed](https://skillfed.io/packages/multiset) · [View on PyPI](https://pypi.org/project/multiset/)