From 29c12a377ffc0c22de3103d52783825124876e1c Mon Sep 17 00:00:00 2001 From: Harsh Raj Singhania <40535627+HarshRajSinghania@users.noreply.github.com> Date: Thu, 10 Sep 2026 00:09:40 +0530 Subject: [PATCH 1/2] sorts: type comb sort for comparable items --- sorts/comb_sort.py | 15 +++++++++++++-- tests/test_sorts.py | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sorts/comb_sort.py b/sorts/comb_sort.py index 72caeb9c7350..7d8defed0190 100644 --- a/sorts/comb_sort.py +++ b/sorts/comb_sort.py @@ -18,8 +18,14 @@ python comb_sort.py """ +from typing import Protocol -def comb_sort(data: list) -> list: + +class Comparable(Protocol): + def __lt__(self, other: object, /) -> bool: ... + + +def comb_sort[T: Comparable](data: list[T]) -> list[T]: """Pure implementation of comb sort algorithm in Python :param data: mutable collection with comparable items :return: the same collection in ascending order @@ -32,7 +38,12 @@ def comb_sort(data: list) -> list: [-15, -7, 0, 2, 3, 8, 45, 99] >>> comb_sort([2, 0, 3, 4, 5, 6, 1]) [0, 1, 2, 3, 4, 5, 6] - """ + + >>> comb_sort(["d", "a", "c", "b"]) + ['a', 'b', 'c', 'd'] + >>> comb_sort([2.5, -1.0, 0.0]) + [-1.0, 0.0, 2.5] +""" shrink_factor = 1.3 gap = len(data) completed = False diff --git a/tests/test_sorts.py b/tests/test_sorts.py index caa4b31cac81..d6351c789353 100644 --- a/tests/test_sorts.py +++ b/tests/test_sorts.py @@ -96,6 +96,7 @@ def test_sort_matches_builtin(sort, case): bubble_sort_iterative, bubble_sort_recursive, insertion_sort, + comb_sort, ], ids=lambda f: f.__name__, ) From dfc646857e0ad9e267df0cde845254a843fa0e78 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 9 Sep 2026 18:40:13 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/comb_sort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorts/comb_sort.py b/sorts/comb_sort.py index 7d8defed0190..bbe57234ffe8 100644 --- a/sorts/comb_sort.py +++ b/sorts/comb_sort.py @@ -43,7 +43,7 @@ def comb_sort[T: Comparable](data: list[T]) -> list[T]: ['a', 'b', 'c', 'd'] >>> comb_sort([2.5, -1.0, 0.0]) [-1.0, 0.0, 2.5] -""" + """ shrink_factor = 1.3 gap = len(data) completed = False