An implementation of a multiset.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file multiset-3.2.0.tar.gz
.
File metadata
- Download URL: multiset-3.2.0.tar.gz
- Upload date:
- Size: 34.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c59a786284b9c339df4f219dcbb4ce5f44d3ac1b20f922636c4d789e89cf7b5 |
|
MD5 | b2666dd1345b0de5d2366c1c71f2beed |
|
BLAKE2b-256 | fe4f72e53b7ba1d54d2243521d3548a49a3dedd85d31df2eabf44bcc6414f18f |
File details
Details for the file multiset-3.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: multiset-3.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d31c6737f537d326835b55be72d0b2e2cf368c874a58cc87879f349273841a1a |
|
MD5 | 8f953bc4f0577eda957198af2ada0d75 |
|
BLAKE2b-256 | 1568860e006b22a7fcbb4b198a988a4df51672a65a43f59148f617b6fe9a49ad |