All Projects → mlenzen → collections-extended

mlenzen / collections-extended

Licence: Apache-2.0 license
Extra Python Collections - bags (multisets), setlists (unique list / indexed set), RangeMap and IndexedDict

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to collections-extended

Best Of Jupyter
🏆 A ranked list of awesome Jupyter Notebook, Hub and Lab projects (extensions, kernels, tools). Updated weekly.
Stars: ✭ 200 (+387.8%)
Mutual labels:  collections
site
Enqueue Zero is creating code principles.
Stars: ✭ 64 (+56.1%)
Mutual labels:  collections
pyfuncol
Functional collections extension functions for Python
Stars: ✭ 32 (-21.95%)
Mutual labels:  collections
.net Big O Algorithm Complexity Cheat Sheet
Big-O complexities of common algorithms used in .NET and Computer Science.
Stars: ✭ 215 (+424.39%)
Mutual labels:  collections
Awesome Python
A curated list of awesome Python frameworks, libraries, software and resources
Stars: ✭ 110,263 (+268834.15%)
Mutual labels:  collections
indicium
🔎 A simple in-memory search for collections and key-value stores.
Stars: ✭ 41 (+0%)
Mutual labels:  collections
Mad Metasploit
Metasploit custom modules, plugins, resource script and.. awesome metasploit collection
Stars: ✭ 200 (+387.8%)
Mutual labels:  collections
arctos
Arctos is a museum collections management system
Stars: ✭ 39 (-4.88%)
Mutual labels:  collections
vec
Fast, safe mutable dynamic arrays for OCaml
Stars: ✭ 25 (-39.02%)
Mutual labels:  collections
ugo
Simple and expressive toolbox written in Go
Stars: ✭ 27 (-34.15%)
Mutual labels:  collections
Java Interview Questions
1000+ Java Interview Questions
Stars: ✭ 212 (+417.07%)
Mutual labels:  collections
Staticvec
Implements a fixed-capacity stack-allocated Vec alternative backed by an array, using const generics.
Stars: ✭ 236 (+475.61%)
Mutual labels:  collections
SSComposeCookBook
A Collection of major Jetpack compose UI components which are commonly used.🎉🔝👌
Stars: ✭ 386 (+841.46%)
Mutual labels:  collections
Codejam
Set of handy reusable .NET components that can simplify your daily work and save your time when you copy and paste your favorite helper methods and classes from one project to another
Stars: ✭ 217 (+429.27%)
Mutual labels:  collections
v2ex-collections-search
v2ex收藏搜索
Stars: ✭ 21 (-48.78%)
Mutual labels:  collections
Awesome Deep Learning And Machine Learning Questions
【不定期更新】收集整理的一些网站中(如知乎、Quora、Reddit、Stack Exchange等)与深度学习、机器学习、强化学习、数据科学相关的有价值的问题
Stars: ✭ 203 (+395.12%)
Mutual labels:  collections
awesome-pinescript
A Comprehensive Collection of Everything Related to Tradingview Pine Script.
Stars: ✭ 563 (+1273.17%)
Mutual labels:  collections
ReactiveDataDisplayManager
No description or website provided.
Stars: ✭ 35 (-14.63%)
Mutual labels:  collections
awesome-hive
A curated list of awesome Hive resources.
Stars: ✭ 20 (-51.22%)
Mutual labels:  collections
HelloWorlds
Hello-World program in most programming languages
Stars: ✭ 102 (+148.78%)
Mutual labels:  collections

README

Coverage Downloads
Documentation:
https://collections-extended.lenzm.net/
GitHub:
https://github.com/mlenzen/collections-extended
PyPI:
https://pypi.python.org/pypi/collections-extended

Overview

collections_extended is a pure Python module with no dependencies providing extra collections. The new collections include bags AKA multisets, setlists AKA unique lists or ordered sets, a bijection, a RangeMap which is a mapping from ranges to values, and an IndexedDict class. There are also frozen (hashable) varieties of bags and setlists.

Compatible with and tested against CPython 3.6, 3.7, 3.8, 3.9, 3.10, PyPy3.6, PyPy3.7 & PyPy3.8.

Getting Started

>>> from collections_extended import bag, setlist, bijection, RangeMap, IndexedDict
>>> 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

>>> version = RangeMap()
>>> version[date(2017, 10, 20): date(2017, 10, 27)] = '0.10.1'
>>> version[date(2017, 10, 27): date(2018, 2, 14)] = '1.0.0'
>>> version[date(2018, 2, 14):] = '1.0.1'
>>> version[date(2017, 10, 24)]
'0.10.1'
>>> version[date(2018, 7, 1)]
'1.0.1'
>>> version[date(2018, 6, 30):] = '1.0.2'
>>> version[date(2018, 7, 1)]
'1.0.2'

>>> idict = IndexedDict()
>>> idict['a'] = "A"
>>> idict['b'] = "B"
>>> idict['c'] = "C"
>>> idict.get(key='a')
'A'
>>> idict.get(index=2)
'C'
>>> idict.index('b')
1

Installation

pip install collections-extended

Usage

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

New Collections

There are seven new collections 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)
IndexedDict
A mapping that keeps insertion order and allows access by index.

Python 2

The package no longer supports Python 2. The last version to support Python 2.7, 3.4 & 3.5 was 1.0. No new feature releases will be done for 1.x but any significant bugs that come up may be fixed.

Author:Michael Lenzen
Copyright:2022 Michael Lenzen
License:Apache License, Version 2.0
Project Homepage:https://github.com/mlenzen/collections-extended
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].