n | from typing import MutableSequence, TypeVar, cast | n | from typing import cast, List, TypeVar, Callable |
| T = TypeVar('T') | | T = TypeVar('T') |
t | Sortable = MutableSequence[T] | t | Sortable = List[T] |
| | | |
| def bubble(sequence: Sortable) -> Sortable: | | def bubble(sequence: Sortable) -> Sortable: |
| n = len(sequence) | | n = len(sequence) |
| for i in range(n): | | for i in range(n): |
| for j in range(0, n - i - 1): | | for j in range(0, n - i - 1): |
| if sequence[j] > sequence[j + 1]: | | if sequence[j] > sequence[j + 1]: |
| sequence[j], sequence[j + 1] = (sequence[j + 1], sequence[j]) | | sequence[j], sequence[j + 1] = (sequence[j + 1], sequence[j]) |
| return sequence | | return sequence |