Extra Python Collections - bags (multisets) and setlists (ordered sets)
Project description
Documentation: http://python-collections-extended.lenzm.net
GitHub: https://github.com/mlenzen/collections-extended
PyPI: https://pypi.python.org/pypi/collections-extended
Overview
This package includes one module - collections_extended. This module provides a bag class, AKA multiset, and a setlist class, which is a list of unique elements / ordered set. There are also frozen (hashable) varieties of each included.
Tested against Python 2.6, 2.7, 3.2, 3.3, 3.4 & PyPy.
Getting Started
>>> from collections_extended import bag, setlist
>>> 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
ValueError
>>> sl.index('d')
4
Installation
pip install collections-extended
Usage
from collections_extended import bag, frozenbag, setlist, frozensetlist
Classes
There are four 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.
Collection Factory
A Collection factory is provided where you can specify whether you want the Collection returned to be mutable, have unique elements and/or be ordered. If an Iterable object is passed the Collection will be filled from it, otherwise it will be empty.
collection(it = None, mutable=True, unique=False, ordered=False)
- Author:
Michael Lenzen
- Copyright:
2015 Michael Lenzen
- License:
Apache License, Version 2.0
- Project Homepage:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file collections-extended-0.2.0.tar.gz
.
File metadata
- Download URL: collections-extended-0.2.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5baea9679e6a928c5f0e5cf9d749457b71c96c1fa2b5f27015a4ea08cb5f655 |
|
MD5 | 1d42e7213e155c4d4dc9ecd31b6bcfe4 |
|
BLAKE2b-256 | 9e3e9199bd84d1b747263b3717ebc3852b9c4de8b36da5f43e2290c7bf4a7ae3 |
File details
Details for the file collections_extended-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: collections_extended-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17eac1e2f308dfe951b21b4317587ffc1b2aea9699fcf4b7cecf77e95bc1abc0 |
|
MD5 | 102c422951dc86524363388cf550b46f |
|
BLAKE2b-256 | af171d848244d0f5070884eca257e947fbbb4385c63b50607bde25a3a3dba0c9 |