--- id: sortedcontainers version: "2.4.0" license: Apache 2.0 license_treatment: permissive maintenance: abandoned --- # sortedcontainers — Sorted Containers -- Sorted List, Sorted Dict, Sorted Set License: permissive · Maintenance: abandoned · Popularity: top 1,000 on PyPI ## Install pip install sortedcontainers uv add sortedcontainers poetry add sortedcontainers ## Description Python Sorted Containers ======================== `Sorted Containers`_ is an Apache2 licensed `sorted collections library`_, written in pure-Python, and fast as C-extensions. 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! .. code-block:: 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']) >>>... [View on SkillFed](https://skillfed.io/packages/sortedcontainers) · [View on PyPI](https://pypi.org/project/sortedcontainers/)