Python Sorted Containers

Sorted Containers is an Apache2 licensed sorted collections library, written in pure-Python, and fast as C-extensions.

Contributors


Python Sorted Containers is all of us

Our contributors 5

Thank you for supporting Python Sorted Containers.

Grant Jenks

Admin

$100 USD

Jacob Brazeal

backer

$50 USD

Budget


Transparent and open finances.

Donation to close out the account

Category
Donations & Sponsorships
from Conferences to Python Sorted Containers
-$183.82 USD
Paid

Credit from Sam Marrable to Python Sorted Containers using a Gift Card from Triplebyte

+$35.00USD
Completed
Contribution #60128

Credit from Ethan Estrada to Python Sorted Containers using a Gift Card from Triplebyte

+$25.00USD
Completed
Contribution #57112
$
Today’s balance

--.-- USD

Total raised

$268.50 USD

Total disbursed

$268.50 USD

Estimated annual budget

--.-- USD

About


Python's standard library is great until you need a sorted collections type. Many will attest that you can get really far without one, but the moment you really need a sorted list, sorted dict, or sorted set, you're faced with a dozen different implementations, most using C-extensions without great documentation and benchmarking.

In Python, we can do better. And we can do it in pure-Python!

>>> from sortedcontainers import SortedList
>>> sl = SortedList(['e', 'a', 'c', 'd', 'b'])
>>> sl
SortedList(['a', 'b', 'c', 'd', 'e'])
>>> sl *= 10_000_000
>>> sl.count('c')
10000000
>>> sl[-3:]
['e', 'e', 'e']
>>> from sortedcontainers import SortedDict
>>> sd = SortedDict({'c': 3, 'a': 1, 'b': 2})
>>> sd
SortedDict({'a': 1, 'b': 2, 'c': 3})
>>> sd.popitem(index=-1)
('c', 3)
>>> from sortedcontainers import SortedSet
>>> ss = SortedSet('abracadabra')
>>> ss
SortedSet(['a', 'b', 'c', 'd', 'r'])
>>> ss.bisect_left('c')
2

All of the operations shown above run in faster than linear time. The above demo also takes nearly a gigabyte of memory to run. When the sorted list is multiplied by ten million, it stores ten million references to each of "a" through "e". Each reference requires eight bytes in the sorted container. That's pretty hard to beat as it's the cost of a pointer to each object. It's also 66% less overhead than a typical binary tree implementation (e.g. Red-Black Tree, AVL-Tree, AA-Tree, Splay-Tree, Treap, etc.) for which every node must also store two pointers to children nodes.

Sorted Containers takes all of the work out of Python sorted collections - making your deployment and use of Python easy. There's no need to install a C compiler or pre-build and distribute custom extensions. Performance is a feature and testing has 100% coverage with unit tests and hours of stress.

Our team