Усович Алексей, 530 группа StrictSort 1709
Воробьев Сергей Юрьевич 530 StrictSort 1690
f1from typing import Protocol, TypeVar, Callable, runtime_checkablef1from typing import Protocol, TypeVar, Callable, runtime_checkable
2from collections.abc import MutableSequence, Sized2from collections.abc import MutableSequence, Sized
33
4@runtime_checkable4@runtime_checkable
n5class LessThen(Protocol):n5class SupportsLessThan(Protocol):
66
7    def __lt__(self, other: object) -> bool:7    def __lt__(self, other: object) -> bool:
8        ...8        ...
n9Comparable = TypeVar('Comparable', bound=LessThen)n9Comparable = TypeVar('Comparable', bound=SupportsLessThan)
10Sortable = MutableSequence[Comparable]10Sortable = MutableSequence[Comparable]
1111
n12def defkey(element: Comparable) -> LessThen:n12def defkey(element: Comparable) -> SupportsLessThan:
13    if isinstance(element, Sized):13    if isinstance(element, Sized):
14        return len(element)14        return len(element)
15    return element15    return element
1616
t17def strictsort(inp: Sortable[Comparable], key: Callable[[Comparable], Let17def strictsort(seq: Sortable[Comparable], key: Callable[[Comparable], Su
>ssThen]=defkey) -> Sortable[Comparable]:>pportsLessThan]=defkey) -> Sortable[Comparable]:
18    lst = list(inp)18    tmp = list(seq)
19    lst.sort(key=key)19    tmp.sort(key=key)
20    inp[:] = lst20    seq[:] = tmp
21    return inp21    return seq
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op