f | from collections.abc import MutableSequence, Sized, Callable | f | from collections.abc import MutableSequence, Sized, Callable |
| from typing import Protocol, Any | | from typing import Protocol, Any |
| | | |
| class Comparable(Protocol): | | class Comparable(Protocol): |
| | | |
| def __lt__(self, other: Any) -> bool: | | def __lt__(self, other: Any) -> bool: |
| pass | | pass |
| Sortable = MutableSequence[Comparable] | | Sortable = MutableSequence[Comparable] |
| | | |
| def defkey(element: Comparable) -> Comparable: | | def defkey(element: Comparable) -> Comparable: |
| if isinstance(element, Sized): | | if isinstance(element, Sized): |
| return len(element) | | return len(element) |
t | | t | else: |
| return element | | return element |
| | | |
| def strictsort(seq: Sortable, key: Callable[[Comparable], Comparable]=de | | def strictsort(seq: Sortable, key: Callable[[Comparable], Comparable]=de |
| fkey) -> Sortable: | | fkey) -> Sortable: |
| return sorted(seq, key=key) | | return sorted(seq, key=key) |