Skip to content

Commit 7581bb5

Browse files
Document the comparison operators recursive quick sort actually uses
The partition uses <= and >, so the Comparable protocol should declare __le__ and __gt__ as well as __lt__.
1 parent 49d08e3 commit 7581bb5

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎sorts/recursive_quick_sort.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
class Comparable(Protocol):
1515
def __lt__(self, other: Any, /) -> bool: ...
1616

17+
def __le__(self, other: Any, /) -> bool: ...
18+
19+
def __gt__(self, other: Any, /) -> bool: ...
20+
1721

1822
def quick_sort[T: Comparable](data: list[T]) -> list[T]:
1923
"""Sort a list of mutually comparable items with recursive quick sort.

0 commit comments

Comments
 (0)