sorts.circle_sort

This is a Python implementation of the circle sort algorithm

For doctests run following command: python3 -m doctest -v circle_sort.py

For manual testing run: python3 circle_sort.py

Attributes

user_input

Classes

Comparable

Base class for protocol classes.

Functions

circle_sort(→ collections.abc.MutableSequence[T])

A pure Python implementation of circle sort algorithm

Module Contents

class sorts.circle_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.circle_sort.circle_sort[T: Comparable](collection: collections.abc.MutableSequence[T]) collections.abc.MutableSequence[T]

A pure Python implementation of circle sort algorithm

Parameters:

collection – a mutable collection of comparable items in any order

Returns:

the same collection in ascending order

Examples: >>> circle_sort([0, 5, 3, 2, 2]) [0, 2, 2, 3, 5] >>> circle_sort([]) [] >>> circle_sort([-2, 5, 0, -45]) [-45, -2, 0, 5] >>> circle_sort([“d”, “a”, “c”, “b”]) [‘a’, ‘b’, ‘c’, ‘d’] >>> circle_sort([2.5, -1.0, 0.0]) [-1.0, 0.0, 2.5] >>> circle_sort([1, “a”]) Traceback (most recent call last):

TypeError: ‘<’ not supported between instances of ‘str’ and ‘int’ >>> collections = ([], [0, 5, 3, 2, 2], [-2, 5, 0, -45]) >>> all(sorted(collection) == circle_sort(collection) for collection in collections) True

sorts.circle_sort.user_input