{"id":13392882,"url":"https://github.com/grantjenks/python-sortedcontainers","last_synced_at":"2026-07-11T02:17:02.534Z","repository":{"id":14433554,"uuid":"17144859","full_name":"grantjenks/python-sortedcontainers","owner":"grantjenks","description":"Python Sorted Container Types: Sorted List, Sorted Dict, and Sorted Set","archived":false,"fork":false,"pushed_at":"2024-03-08T17:47:09.000Z","size":78483,"stargazers_count":3965,"open_issues_count":37,"forks_count":232,"subscribers_count":34,"default_branch":"master","last_synced_at":"2026-07-06T11:30:22.790Z","etag":null,"topics":["data-types","dict","list","python","set","sorted"],"latest_commit_sha":null,"homepage":"http://www.grantjenks.com/docs/sortedcontainers/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"jamesotron/hamlbars","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grantjenks.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-02-24T17:44:20.000Z","updated_at":"2026-07-05T07:08:20.000Z","dependencies_parsed_at":"2024-03-15T02:08:06.732Z","dependency_job_id":"93285ace-e88f-4be6-bf1c-e45821aaba86","html_url":"https://github.com/grantjenks/python-sortedcontainers","commit_stats":{"total_commits":632,"total_committers":25,"mean_commits":25.28,"dds":0.379746835443038,"last_synced_commit":"3ac358631f58c1347f1d6d2d92784117db0f38ed"},"previous_names":["grantjenks/sorted_containers"],"tags_count":41,"template":false,"template_full_name":null,"purl":"pkg:github/grantjenks/python-sortedcontainers","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantjenks%2Fpython-sortedcontainers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantjenks%2Fpython-sortedcontainers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantjenks%2Fpython-sortedcontainers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantjenks%2Fpython-sortedcontainers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grantjenks","download_url":"https://codeload.github.com/grantjenks/python-sortedcontainers/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grantjenks%2Fpython-sortedcontainers/sbom","scorecard":{"id":443665,"data":{"date":"2025-08-11","repo":{"name":"github.com/grantjenks/python-sortedcontainers","commit":"3ac358631f58c1347f1d6d2d92784117db0f38ed"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 1/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/integration.yml:1","Warn: no topLevel permission defined: .github/workflows/release.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"License","score":9,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Warn: project license file does not contain an FSF or OSI license."],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":6,"reason":"4 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: PYSEC-2019-156 / GHSA-xp76-357g-9wqq","Warn: Project is vulnerable to: PYSEC-2023-102","Warn: Project is vulnerable to: PYSEC-2023-114","Warn: Project is vulnerable to: PYSEC-2022-43017 / GHSA-qwmp-2cf2-g9g6"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/integration.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/grantjenks/python-sortedcontainers/integration.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/integration.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/grantjenks/python-sortedcontainers/integration.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/integration.yml:46: update your workflow using https://app.stepsecurity.io/secureworkflow/grantjenks/python-sortedcontainers/integration.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/integration.yml:48: update your workflow using https://app.stepsecurity.io/secureworkflow/grantjenks/python-sortedcontainers/integration.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/grantjenks/python-sortedcontainers/release.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/grantjenks/python-sortedcontainers/release.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/grantjenks/python-sortedcontainers/release.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/integration.yml:30","Warn: pipCommand not pinned by hash: .github/workflows/integration.yml:31","Warn: pipCommand not pinned by hash: .github/workflows/integration.yml:55","Warn: pipCommand not pinned by hash: .github/workflows/integration.yml:56","Warn: pipCommand not pinned by hash: .github/workflows/release.yml:25","Info:   0 out of   6 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned","Info:   0 out of   5 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T06:10:35.027Z","repository_id":14433554,"created_at":"2025-08-19T06:10:35.027Z","updated_at":"2025-08-19T06:10:35.027Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35191767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-06T02:00:07.184Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-types","dict","list","python","set","sorted"],"created_at":"2024-07-30T17:00:38.623Z","updated_at":"2026-07-11T02:17:02.513Z","avatar_url":"https://github.com/grantjenks.png","language":"Python","funding_links":[],"categories":["Uncategorized","Algorithms and Design Patterns","Data Structures","Data Processing","Python","Topics Index","Algorithms and Design Patterns [🔝](#readme)","算法和设计模式","资源列表"],"sub_categories":["Uncategorized","Data Representation","QoL Libraries","算法和设计模式"],"readme":"Python Sorted Containers\n========================\n\n`Sorted Containers`_ is an Apache2 licensed `sorted collections library`_,\nwritten in pure-Python, and fast as C-extensions.\n\nPython's standard library is great until you need a sorted collections\ntype. Many will attest that you can get really far without one, but the moment\nyou **really need** a sorted list, sorted dict, or sorted set, you're faced\nwith a dozen different implementations, most using C-extensions without great\ndocumentation and benchmarking.\n\nIn Python, we can do better. And we can do it in pure-Python!\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from sortedcontainers import SortedList\n    \u003e\u003e\u003e sl = SortedList(['e', 'a', 'c', 'd', 'b'])\n    \u003e\u003e\u003e sl\n    SortedList(['a', 'b', 'c', 'd', 'e'])\n    \u003e\u003e\u003e sl *= 10_000_000\n    \u003e\u003e\u003e sl.count('c')\n    10000000\n    \u003e\u003e\u003e sl[-3:]\n    ['e', 'e', 'e']\n    \u003e\u003e\u003e from sortedcontainers import SortedDict\n    \u003e\u003e\u003e sd = SortedDict({'c': -3, 'a': 1, 'b': 2})\n    \u003e\u003e\u003e sd\n    SortedDict({'a': 1, 'b': 2, 'c': -3})\n    \u003e\u003e\u003e sd.popitem(index=-1)\n    ('c', -3)\n    \u003e\u003e\u003e from sortedcontainers import SortedSet\n    \u003e\u003e\u003e ss = SortedSet('abracadabra')\n    \u003e\u003e\u003e ss\n    SortedSet(['a', 'b', 'c', 'd', 'r'])\n    \u003e\u003e\u003e ss.bisect_left('c')\n    2\n\nAll of the operations shown above run in faster than linear time. The above\ndemo also takes nearly a gigabyte of memory to run. When the sorted list is\nmultiplied by ten million, it stores ten million references to each of \"a\"\nthrough \"e\". Each reference requires eight bytes in the sorted\ncontainer. That's pretty hard to beat as it's the cost of a pointer to each\nobject. It's also 66% less overhead than a typical binary tree implementation\n(e.g. Red-Black Tree, AVL-Tree, AA-Tree, Splay-Tree, Treap, etc.) for which\nevery node must also store two pointers to children nodes.\n\n`Sorted Containers`_ takes all of the work out of Python sorted collections -\nmaking your deployment and use of Python easy. There's no need to install a C\ncompiler or pre-build and distribute custom extensions. Performance is a\nfeature and testing has 100% coverage with unit tests and hours of stress.\n\n.. _`Sorted Containers`: http://www.grantjenks.com/docs/sortedcontainers/\n.. _`sorted collections library`: http://www.grantjenks.com/docs/sortedcontainers/\n\nTestimonials\n------------\n\n**Alex Martelli**, `Fellow of the Python Software Foundation`_\n\n\"Good stuff! ... I like the `simple, effective implementation`_ idea of\nsplitting the sorted containers into smaller \"fragments\" to avoid the O(N)\ninsertion costs.\"\n\n**Jeff Knupp**, `author of Writing Idiomatic Python and Python Trainer`_\n\n\"That last part, \"fast as C-extensions,\" was difficult to believe. I would need\nsome sort of `Performance Comparison`_ to be convinced this is true. The author\nincludes this in the docs. It is.\"\n\n**Kevin Samuel**, `Python and Django Trainer`_\n\nI'm quite amazed, not just by the code quality (it's incredibly readable and\nhas more comment than code, wow), but the actual amount of work you put at\nstuff that is *not* code: documentation, benchmarking, implementation\nexplanations. Even the git log is clean and the unit tests run out of the box\non Python 2 and 3.\n\n**Mark Summerfield**, a short plea for `Python Sorted Collections`_\n\nPython's \"batteries included\" standard library seems to have a battery\nmissing. And the argument that \"we never had it before\" has worn thin. It is\ntime that Python offered a full range of collection classes out of the box,\nincluding sorted ones.\n\n`Sorted Containers`_ is used in popular open source projects such as:\n`Zipline`_, an algorithmic trading library from Quantopian; `Angr`_, a binary\nanalysis platform from UC Santa Barbara; `Trio`_, an async I/O library; and\n`Dask Distributed`_, a distributed computation library supported by Continuum\nAnalytics.\n\n.. _`Fellow of the Python Software Foundation`: https://en.wikipedia.org/wiki/Alex_Martelli\n.. _`simple, effective implementation`: http://www.grantjenks.com/docs/sortedcontainers/implementation.html\n.. _`author of Writing Idiomatic Python and Python Trainer`: https://jeffknupp.com/\n.. _`Python and Django Trainer`: https://www.elephorm.com/formateur/kevin-samuel\n.. _`Python Sorted Collections`: http://www.qtrac.eu/pysorted.html\n.. _`Zipline`: https://github.com/quantopian/zipline\n.. _`Angr`: https://github.com/angr/angr\n.. _`Trio`: https://github.com/python-trio/trio\n.. _`Dask Distributed`: https://github.com/dask/distributed\n\nFeatures\n--------\n\n- Pure-Python\n- Fully documented\n- Benchmark comparison (alternatives, runtimes, load-factors)\n- 100% test coverage\n- Hours of stress testing\n- Performance matters (often faster than C implementations)\n- Compatible API (nearly identical to older blist and bintrees modules)\n- Feature-rich (e.g. get the five largest keys in a sorted dict: d.keys()[-5:])\n- Pragmatic design (e.g. SortedSet is a Python set with a SortedList index)\n- Developed on Python 3.10\n- Tested with CPython 3.7, 3.8, 3.9, 3.10, 3.11, 3.12 and PyPy3\n- Tested on Linux, Mac OSX, and Windows\n\n.. image:: https://github.com/grantjenks/python-sortedcontainers/workflows/integration/badge.svg\n   :target: http://www.grantjenks.com/docs/sortedcontainers/\n\n.. image:: https://github.com/grantjenks/python-sortedcontainers/workflows/release/badge.svg\n   :target: http://www.grantjenks.com/docs/sortedcontainers/\n\nQuickstart\n----------\n\nInstalling `Sorted Containers`_ is simple with `pip\n\u003chttps://pypi.org/project/pip/\u003e`_::\n\n    $ pip install sortedcontainers\n\nYou can access documentation in the interpreter with Python's built-in `help`\nfunction. The `help` works on modules, classes and methods in `Sorted\nContainers`_.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import sortedcontainers\n    \u003e\u003e\u003e help(sortedcontainers)\n    \u003e\u003e\u003e from sortedcontainers import SortedDict\n    \u003e\u003e\u003e help(SortedDict)\n    \u003e\u003e\u003e help(SortedDict.popitem)\n\nDocumentation\n-------------\n\nComplete documentation for `Sorted Containers`_ is available at\nhttp://www.grantjenks.com/docs/sortedcontainers/\n\nUser Guide\n..........\n\nThe user guide provides an introduction to `Sorted Containers`_ and extensive\nperformance comparisons and analysis.\n\n- `Introduction`_\n- `Performance Comparison`_\n- `Load Factor Performance Comparison`_\n- `Runtime Performance Comparison`_\n- `Simulated Workload Performance Comparison`_\n- `Performance at Scale`_\n\n.. _`Introduction`: http://www.grantjenks.com/docs/sortedcontainers/introduction.html\n.. _`Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance.html\n.. _`Load Factor Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-load.html\n.. _`Runtime Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-runtime.html\n.. _`Simulated Workload Performance Comparison`: http://www.grantjenks.com/docs/sortedcontainers/performance-workload.html\n.. _`Performance at Scale`: http://www.grantjenks.com/docs/sortedcontainers/performance-scale.html\n\nCommunity Guide\n...............\n\nThe community guide provides information on the development of `Sorted\nContainers`_ along with support, implementation, and history details.\n\n- `Development and Support`_\n- `Implementation Details`_\n- `Release History`_\n\n.. _`Development and Support`: http://www.grantjenks.com/docs/sortedcontainers/development.html\n.. _`Implementation Details`: http://www.grantjenks.com/docs/sortedcontainers/implementation.html\n.. _`Release History`: http://www.grantjenks.com/docs/sortedcontainers/history.html\n\nAPI Documentation\n.................\n\nThe API documentation provides information on specific functions, classes, and\nmodules in the `Sorted Containers`_ package.\n\n- `Sorted List`_\n- `Sorted Dict`_\n- `Sorted Set`_\n\n.. _`Sorted List`: http://www.grantjenks.com/docs/sortedcontainers/sortedlist.html\n.. _`Sorted Dict`: http://www.grantjenks.com/docs/sortedcontainers/sorteddict.html\n.. _`Sorted Set`: http://www.grantjenks.com/docs/sortedcontainers/sortedset.html\n\nTalks\n-----\n\n- `Python Sorted Collections | PyCon 2016 Talk`_\n- `SF Python Holiday Party 2015 Lightning Talk`_\n- `DjangoCon 2015 Lightning Talk`_\n\n.. _`Python Sorted Collections | PyCon 2016 Talk`: http://www.grantjenks.com/docs/sortedcontainers/pycon-2016-talk.html\n.. _`SF Python Holiday Party 2015 Lightning Talk`: http://www.grantjenks.com/docs/sortedcontainers/sf-python-2015-lightning-talk.html\n.. _`DjangoCon 2015 Lightning Talk`: http://www.grantjenks.com/docs/sortedcontainers/djangocon-2015-lightning-talk.html\n\nResources\n---------\n\n- `Sorted Containers Documentation`_\n- `Sorted Containers at PyPI`_\n- `Sorted Containers at Github`_\n- `Sorted Containers Issue Tracker`_\n\n.. _`Sorted Containers Documentation`: http://www.grantjenks.com/docs/sortedcontainers/\n.. _`Sorted Containers at PyPI`: https://pypi.org/project/sortedcontainers/\n.. _`Sorted Containers at Github`: https://github.com/grantjenks/python-sortedcontainers\n.. _`Sorted Containers Issue Tracker`: https://github.com/grantjenks/python-sortedcontainers/issues\n\nSorted Containers License\n-------------------------\n\nCopyright 2014-2024 Grant Jenks\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrantjenks%2Fpython-sortedcontainers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrantjenks%2Fpython-sortedcontainers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrantjenks%2Fpython-sortedcontainers/lists"}