sorts.shell_sort

https://en.wikipedia.org/wiki/Shellsort#Pseudocode

Attributes

user_input

Classes

Comparable

Base class for protocol classes.

Functions

shell_sort(→ list[T])

Pure implementation of shell sort algorithm in Python.

Module Contents

class sorts.shell_sort.Comparable

Bases: Protocol

Base 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: Any, /) bool
sorts.shell_sort.shell_sort[T: Comparable](collection: list[T]) list[T]

Pure implementation of shell sort algorithm in Python.

Parameters:

collection – Some mutable ordered collection with heterogeneous

comparable items inside :return: the same collection ordered by ascending

Examples: >>> shell_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] >>> shell_sort([]) [] >>> shell_sort([-2, -5, -45]) [-45, -5, -2] >>> shell_sort([“c”, “a”, “b”]) [‘a’, ‘b’, ‘c’] >>> shell_sort([2.5, -1.0, 0.0]) [-1.0, 0.0, 2.5] >>> shell_sort([0, 5, 3, 2, 2]) == sorted([0, 5, 3, 2, 2]) True >>> shell_sort([“c”, “a”, “b”]) == sorted([“c”, “a”, “b”]) True

sorts.shell_sort.user_input