Skip to main content
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, provides 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 PyPy & PyPy3.

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:

2015 Michael Lenzen

License:

Apache License, Version 2.0

Project Homepage:

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

Release files for collections-extended 0.5.1

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.5.1
File Size Uploaded
collections-extended-0.5.1.tar.gz 31.1 kB Details

Built distribution (wheel)

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

Total release size: 44.9 kB

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

Download URL collections-extended-0.5.1.tar.gz
Size 31.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dcef272143021b39fed4ab6e3ae45dcc812aac1af7cd3c0b138bdcb19a938e8a
BLAKE2b-256 checksum
How to use checksums
8cf2463f76ad47bc800dd494375f6d2d271b76686a0acf94e7680bfaf6a2cc11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL collections_extended-0.5.1-py2.py3-none-any.whl
Size 13.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9f7c88d0029302eeabd1fbafbf4dc2ec87029b97322b78dbe50886e1001f2b1f
BLAKE2b-256 checksum
How to use checksums
ad716036354c02797e2a63b93d545765e7cfe8db43beca00fd668c16d541b50c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.10.1

2 release files

0.9.0

2 release files

0.8.2

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.2

2 release files

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.0

1 release file

0.3.1

2 release files

0.3.0

1 release file

0.2.0

2 release files

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