sorts.unknown_sort¶
Python implementation of a sort algorithm. Best Case Scenario : O(n) Worst Case Scenario : O(n^2) because native Python functions:min, max and remove are already O(n)
Attributes¶
Classes¶
Base class for protocol classes. |
Functions¶
|
Pure implementation of the fastest merge sort algorithm in Python |
Module Contents¶
- class sorts.unknown_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.unknown_sort.merge_sort[T: Comparable](collection: list[T]) list[T]¶
Pure implementation of the fastest merge sort algorithm in Python
- Parameters:
collection – some mutable ordered collection with heterogeneous
comparable items inside :return: a collection ordered by ascending
Examples: >>> merge_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5]
>>> merge_sort([]) []
>>> merge_sort([-2, -5, -45]) [-45, -5, -2]
>>> merge_sort(['d', 'a', 'b', 'e']) == sorted(['d', 'a', 'b', 'e']) True
>>> merge_sort([1.1, 3.3, 5.5, 2.2, 4.4]) [1.1, 2.2, 3.3, 4.4, 5.5]
>>> merge_sort([1, "a"]) Traceback (most recent call last): ... TypeError: '<' not supported between instances of 'str' and 'int'
- sorts.unknown_sort.user_input¶