sorts.circle_sort ================= .. py:module:: sorts.circle_sort .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: sorts.circle_sort.user_input Classes ------- .. autoapisummary:: sorts.circle_sort.Comparable Functions --------- .. autoapisummary:: sorts.circle_sort.circle_sort Module Contents --------------- .. py:class:: Comparable Bases: :py:obj:`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: ... .. py:method:: __lt__(other: Any, /) -> bool .. py:function:: circle_sort[T: Comparable](collection: collections.abc.MutableSequence[T]) -> collections.abc.MutableSequence[T] A pure Python implementation of circle sort algorithm :param collection: a mutable collection of comparable items in any order :return: 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 .. py:data:: user_input