n | from typing import cast, List, TypeVar, Callable | n | from typing import MutableSequence, TypeVar, cast |
| T = TypeVar('T') | | T = TypeVar('T') |
t | Sortable = List[T] | t | Sortable = MutableSequence[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 |