Giter Club home page Giter Club logo

multiset's Introduction

multiset

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 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.

multiset's People

Contributors

wheerd avatar dependabot[bot] avatar dependabot-preview[bot] avatar lonnen avatar mikefhay avatar razi96 avatar tjni avatar bakert avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.