{"id":374,"library":"sortedcontainers","title":"Sorted Containers","description":"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))","status":"active","version":"2.4.0","language":"python","source_language":"en","source_url":"https://github.com/grantjenks/python-sortedcontainers","tags":["sortedcontainers","Python","data structures","SortedList","SortedDict","SortedSet"],"install":[{"cmd":"pip install sortedcontainers","lang":"bash","label":"Install Sorted Containers"}],"dependencies":[],"imports":[{"note":"Correct import path for SortedList.","symbol":"SortedList","correct":"from sortedcontainers import SortedList"},{"note":"Correct import path for SortedDict.","symbol":"SortedDict","correct":"from sortedcontainers import SortedDict"},{"note":"Correct import path for SortedSet.","symbol":"SortedSet","correct":"from sortedcontainers import SortedSet"}],"quickstart":{"code":"from sortedcontainers import SortedList, SortedDict, SortedSet\n\n# SortedList\nsl = SortedList(['e', 'a', 'c', 'd', 'b'])\nprint(sl)  # Output: SortedList(['a', 'b', 'c', 'd', 'e'])\n\n# SortedDict\nsd = SortedDict({'c': -3, 'a': 1, 'b': 2})\nprint(sd)  # Output: SortedDict({'a': 1, 'b': 2, 'c': -3})\n\n# SortedSet\nss = SortedSet([5, 4, 3, 2, 1])\nprint(ss)  # Output: SortedSet([1, 2, 3, 4, 5])\n\n# Adding elements\nsl.add('f')\nprint(sl)  # Output: SortedList(['a', 'b', 'c', 'd', 'e', 'f'])\n\n# Removing elements\nsl.remove('a')\nprint(sl)  # Output: SortedList(['b', 'c', 'd', 'e', 'f'])\n\n# Accessing elements\nprint(sl[0])  # Output: 'b'\nprint(sl[-1])  # Output: 'f'","lang":"python","description":"A quickstart guide demonstrating the usage of SortedList, SortedDict, and SortedSet from the sortedcontainers library."},"warnings":[{"fix":"Review and update codebases to accommodate the new methods in SortedDict.","message":"In version 2.4.0, SortedDict methods 'or', 'ror', and 'ior' were implemented per PEP 584. Ensure compatibility with existing codebases before upgrading.","severity":"breaking","affected_versions":"2.4.0"},{"fix":"Replace usage of 'iloc' with 'keys()' in SortedDict.","message":"The 'iloc' attribute in SortedDict is deprecated. Use 'SortedDict.keys()' instead.","severity":"deprecated","affected_versions":"2.4.0"}],"env_vars":null,"last_verified":"2026-05-12T13:23:42.755Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"pip install sortedcontainers","cause":"The `sortedcontainers` library has not been installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'sortedcontainers'"},{"fix":"my_sorted_list.add(element)","cause":"`SortedList` uses `add()` and `update()` methods to maintain sorted order, unlike standard Python lists which use `append()`.","error":"AttributeError: 'SortedList' object has no attribute 'append'"},{"fix":"Convert unhashable elements to a hashable type (e.g., `tuple()`) before adding them to the `SortedSet`.","cause":"`SortedSet` requires its elements to be hashable (like tuples or numbers), but an unhashable type such as a list was provided.","error":"TypeError: unhashable type: 'list'"},{"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'])`).","cause":"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.","error":"TypeError: '>' not supported between instances of 'dict' and 'dict'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"18.0M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.6,"disk_size":"19.9M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"11.8M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.6,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.9,"disk_size":"11.4M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"17.5M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.4,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}