This package provides a multiset implementation for python.
Overview
A multiset is similar to the builtin set, but it allows an element to occur multiple times. It is an unordered collection of elements which have to be hashable just like in a set. It supports the same methods and operations as set does, e.g. membership test, union, intersection, and (symmetric) difference:
>>> set1 = Multiset('aab')
>>> set2 = Multiset('abc')
>>> sorted(set1 | set2)
['a', 'a', 'b', 'c']
Multisets can be used in combination with sets:
>>> Multiset('aab') >= {'a', 'b'}
True
Multisets are mutable:
>>> set1.update('bc')
>>> sorted(set1)
['a', 'a', 'b', 'b', 'c']
There is an immutable version similar to the frozenset which is also hashable:
>>> set1 = FrozenMultiset('abc')
>>> set2 = FrozenMultiset('abc')
>>> hash(set1) == hash(set2)
True
>>> set1 is set2
False
The implementation is based on a dict that maps the elements to their multiplicity in the multiset. Hence, some dictionary operations are supported.
In contrast to the collections.Counter from the standard library, it has proper support for set operations and only allows positive counts. Also, elements with a zero multiplicity are automatically removed from the multiset.
Installation
Installing multiset is simple with pip:
$ pip install multiset
Documentation
The documentation is available at Read the Docs.
API Documentation
If you are looking for information on a particular method of the Multiset class, have a look at the API Documentation. It is automatically generated from the docstrings.
License
Licensed under the MIT license.
Metadata
Release files for multiset 3.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| multiset-3.2.0.tar.gz | 34.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| multiset-3.2.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 46.0 kB
Release files / multiset-3.2.0.tar.gz
| Download URL | multiset-3.2.0.tar.gz |
|---|---|
| Size | 34.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c59a786284b9c339df4f219dcbb4ce5f44d3ac1b20f922636c4d789e89cf7b5
|
|
BLAKE2b-256 checksum How to use checksums |
fe4f72e53b7ba1d54d2243521d3548a49a3dedd85d31df2eabf44bcc6414f18f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / multiset-3.2.0-py2.py3-none-any.whl
| Download URL | multiset-3.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d31c6737f537d326835b55be72d0b2e2cf368c874a58cc87879f349273841a1a
|
|
BLAKE2b-256 checksum How to use checksums |
1568860e006b22a7fcbb4b198a988a4df51672a65a43f59148f617b6fe9a49ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|