sorts.double_sort¶
Attributes¶
Classes¶
Base class for protocol classes. |
Functions¶
|
This sorting algorithm sorts an array using the principle of bubble sort, |
Module Contents¶
- class sorts.double_sort.Comparable¶
Bases:
ProtocolBase class for protocol classes.
Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).
For example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:
class GenProto[T](Protocol): def meth(self) -> T: ...
- __lt__(other: object, /) bool¶
- sorts.double_sort.double_sort[T: Comparable](collection: list[T]) list[T]¶
This sorting algorithm sorts an array using the principle of bubble sort, but does it both from left to right and right to left. Hence, it’s called “Double sort” :param collection: mutable ordered sequence of comparable elements :return: the same collection in ascending order Examples: >>> double_sort([-1 ,-2 ,-3 ,-4 ,-5 ,-6 ,-7]) [-7, -6, -5, -4, -3, -2, -1] >>> double_sort([]) [] >>> double_sort([-1 ,-2 ,-3 ,-4 ,-5 ,-6]) [-6, -5, -4, -3, -2, -1] >>> double_sort([-3, 10, 16, -42, 29]) == sorted([-3, 10, 16, -42, 29]) True >>> double_sort([“c”, “a”, “b”]) [‘a’, ‘b’, ‘c’] >>> double_sort([2.5, -1, 0.0]) [-1, 0.0, 2.5] >>> double_sort([1, “a”]) Traceback (most recent call last): … TypeError: ‘<’ not supported between instances of ‘str’ and ‘int’
- sorts.double_sort.unsorted¶