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