Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
This package provides a multiset_ implementation for python.
|pypi| |coverage| |build| |docs|
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.
Installing multiset
is simple with pip <http://www.pip-installer.org/>
_::
$ pip install multiset
The documentation is available at Read the Docs
_.
.. _Read the Docs
: http://multiset.readthedocs.io/
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.
.. _API Documentation
: http://multiset.readthedocs.io/en/latest/api.html
Licensed under the MIT_ license.
.. _multiset: https://en.wikipedia.org/wiki/Multiset
.. _set: https://docs.python.org/3.10/library/stdtypes.html#set-types-set-frozenset
.. sets: set
.. frozenset: set
.. _dict: https://docs.python.org/3.10/library/stdtypes.html#mapping-types-dict
.. _collections.Counter
: https://docs.python.org/3.10/library/collections.html#collections.Counter
.. _MIT: https://opensource.org/licenses/MIT
.. |pypi| image:: https://img.shields.io/pypi/v/multiset.svg?style=flat-square&label=latest%20stable%20version :target: https://pypi.python.org/pypi/multiset :alt: Latest version released on PyPi
.. |coverage| image:: https://coveralls.io/repos/github/wheerd/multiset/badge.svg?branch=master :target: https://coveralls.io/github/wheerd/multiset?branch=master :alt: Test coverage
.. |build| image:: https://github.com/wheerd/multiset/workflows/Tests/badge.svg?branch=master :target: https://github.com/wheerd/multiset/actions?query=workflow%3ATests :alt: Build status of the master branch
.. |docs| image:: https://readthedocs.org/projects/multiset/badge/?version=latest :target: http://multiset.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status
FAQs
An implementation of a multiset.
We found that multiset demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.