Skip to main content

README

Build Status Coverage

Documentation: http://collections-extended.lenzm.net/

GitHub: https://github.com/mlenzen/collections-extended

PyPI: https://pypi.python.org/pypi/collections-extended

Overview

collections_extended is a Python module providing a bag class, AKA multiset, a setlist class, which is a unique list or ordered set, a bijection class and RangeMap which is a mapping from ranges to values. There are also frozen (hashable) varieties of bags and setlists.

Tested against Python 2.6, 2.7, 3.1, 3.2, 3.3, 3.4, 3.5, PyPy & PyPy3.

Python 3.1 and 3.2 are unsupported by coverage so they are not included in Travis CI.

Getting Started

>>> from collections_extended import bag, setlist, bijection, RangeMap
>>> from datetime import date
>>> b = bag('abracadabra')
>>> b.count('a')
5
>>> b.remove('a')
>>> b.count('a')
4
>>> 'a' in b
True
>>> b.count('d')
1
>>> b.remove('d')
>>> b.count('d')
0
>>> 'd' in b
False

>>> sl = setlist('abracadabra')
>>> sl
setlist(('a', 'b', 'r', 'c', 'd'))
>>> sl[3]
'c'
>>> sl[-1]
'd'
>>> 'r' in sl  # testing for inclusion is fast
True
>>> sl.index('d')  # so is finding the index of an element
4
>>> sl.insert(1, 'd')  # inserting an element already in raises a ValueError
Traceback (most recent call last):
...
        raise ValueError
ValueError
>>> sl.index('d')
4

>>> bij = bijection({'a': 1, 'b': 2, 'c': 3})
>>> bij.inverse[2]
'b'
>>> bij['a'] = 2
>>> bij == bijection({'a': 2, 'c': 3})
True
>>> bij.inverse[1] = 'a'
>>> bij == bijection({'a': 1, 'c': 3})
True

>>> us_presidents = RangeMap()
>>> us_presidents[date(1993, 1, 20):date(2001, 1, 20)] = 'Bill Clinton'
>>> us_presidents[date(2001, 1, 20):date(2009, 1, 20)] = 'George W. Bush'
>>> us_presidents[date(2009, 1, 20):] = 'Barack Obama'
>>> us_presidents[date(1995, 5, 10)]
'Bill Clinton'
>>> us_presidents[date(2001, 1, 20)]
'George W. Bush'
>>> us_presidents[date(2021, 3, 1)]
'Barack Obama'
>>> us_presidents[date(2017, 1, 20):] = 'Someone New'
>>> us_presidents[date(2021, 3, 1)]
'Someone New'

Installation

pip install collections-extended

Usage

from collections_extended import bag, frozenbag, setlist, frozensetlist, bijection

Classes

There are six new classes provided:

Bags

bag

This is a bag AKA multiset.

frozenbag

This is a frozen (hashable) version of a bag.

Setlists

setlist

An ordered set or a list of unique elements depending on how you look at it.

frozensetlist

This is a frozen (hashable) version of a setlist.

Mappings

bijection

A one-to-one mapping.

RangeMap

A mapping from ranges (of numbers/dates/etc)

Author:

Michael Lenzen

Copyright:

2016 Michael Lenzen

License:

Apache License, Version 2.0

Project Homepage:

https://github.com/mlenzen/collections-extended

Metadata

Release files for collections-extended 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for collections-extended 0.8.0
File Size Uploaded Provenance Actions
collections-extended-0.8.0.tar.gz 11.8 kB Without provenance Details for collections-extended-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for collections-extended 0.8.0
File Interpreter ABI Platform Actions
collections_extended-0.8.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for collections_extended-0.8.0-py2.py3-none-any.whl

Total release size: 27.4 kB

Release files / collections-extended-0.8.0.tar.gz

Download URL collections-extended-0.8.0.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b74f5163638dc4b485b456adf104db15a0c84f71afbed53e078fb9f2ab706060
BLAKE2b-256 checksum
How to use checksums
fa665ac2d0132b456c4568247032e79a2d927a4ae1dc5ba785be41400461e503
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / collections_extended-0.8.0-py2.py3-none-any.whl

Download URL collections_extended-0.8.0-py2.py3-none-any.whl
Size 15.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4c02292237e441fb15a66d107db13f270312c6d64957811712e0a1116e6fc480
BLAKE2b-256 checksum
How to use checksums
50e34f5c55f648d68d90fabbb5a9e026445172dfe5b1c0acd565cc2e137a47d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for collections-extended 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page