Registry / data / sortedcontainers

sortedcontainers

JSON →
library2.4.0pypypi✓ verified 25d ago

A pure-Python library providing fast and easy-to-use implementations of SortedList, SortedDict, and SortedSet data types. Current version: 2.4.0. Release cadence: approximately every 87 days. ([python.libhunt.com](https://python.libhunt.com/sorted_containers-changelog?utm_source=openai))

pip install sortedcontainers
INSTALL
IMPORT
SIG · SORTEDCONTAINERS
S
sortedcontainers
datapythonv2.4.0
Install
1.6s avg
Import
11ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.012s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.010s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SortedList
from sortedcontainers import SortedList
Correct import path for SortedList.
SortedDict
from sortedcontainers import SortedDict
Correct import path for SortedDict.
SortedSet
from sortedcontainers import SortedSet
Correct import path for SortedSet.

A quickstart guide demonstrating the usage of SortedList, SortedDict, and SortedSet from the sortedcontainers library.

from sortedcontainers import SortedList, SortedDict, SortedSet # SortedList sl = SortedList(['e', 'a', 'c', 'd', 'b']) print(sl) # Output: SortedList(['a', 'b', 'c', 'd', 'e']) # SortedDict sd = SortedDict({'c': -3, 'a': 1, 'b': 2}) print(sd) # Output: SortedDict({'a': 1, 'b': 2, 'c': -3}) # SortedSet ss = SortedSet([5, 4, 3, 2, 1]) print(ss) # Output: SortedSet([1, 2, 3, 4, 5]) # Adding elements sl.add('f') print(sl) # Output: SortedList(['a', 'b', 'c', 'd', 'e', 'f']) # Removing elements sl.remove('a') print(sl) # Output: SortedList(['b', 'c', 'd', 'e', 'f']) # Accessing elements print(sl[0]) # Output: 'b' print(sl[-1]) # Output: 'f'
Debug
Known issues
breakingIn version 2.4.0, SortedDict methods 'or', 'ror', and 'ior' were implemented per PEP 584. Ensure compatibility with existing codebases before upgrading.
fix
Review and update codebases to accommodate the new methods in SortedDict.
affects: 2.4.0
deprecatedThe 'iloc' attribute in SortedDict is deprecated. Use 'SortedDict.keys()' instead.
fix
Replace usage of 'iloc' with 'keys()' in SortedDict.
affects: 2.4.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'sortedcontainers'
The `sortedcontainers` library has not been installed in the current Python environment.
fix
pip install sortedcontainers
AttributeError: 'SortedList' object has no attribute 'append'
`SortedList` uses `add()` and `update()` methods to maintain sorted order, unlike standard Python lists which use `append()`.
fix
my_sorted_list.add(element)
TypeError: unhashable type: 'list'
`SortedSet` requires its elements to be hashable (like tuples or numbers), but an unhashable type such as a list was provided.
fix
Convert unhashable elements to a hashable type (e.g., `tuple()`) before adding them to the `SortedSet`.
TypeError: '>' not supported between instances of 'dict' and 'dict'
Elements in a `SortedList` or keys in a `SortedDict` must be comparable, but the provided types (e.g., dictionaries or custom objects without comparison methods) do not have a default ordering.
fix
Define comparison methods (`__lt__`, `__gt__`) for custom objects, or provide a `key` function to the `SortedList` or `SortedDict` constructor to specify how elements should be ordered (e.g., `SortedList(key=lambda x: x['id'])`).
Upgrade
Version history
2.4.0latest on PyPI · released May 16, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
sortedcontainers — pip install sortedcontainers · libregistry