Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

An implementation of a multiset.

Project Description

This package provides a multiset implementation for python.

Latest version released on PyPi Test coverage Build status of the master branch Documentation Status

Overview

A multiset is similar to the builtin set, but it allows an element to occur multiple times. It is an unordered collection of element 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.

Release history Release notifications

This version
History Node

2.1.1

History Node

2.0.3

History Node

2.0.2

History Node

2.0.1

History Node

2.0.0

History Node

1.0.0

History Node

0.2

History Node

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
multiset-2.1.1-py2.py3-none-any.whl (8.8 kB) Copy SHA256 hash SHA256 Wheel 3.6 Apr 13, 2018
multiset-2.1.1.tar.gz (33.2 kB) Copy SHA256 hash SHA256 Source None Apr 13, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page