n | from typing import List, TypeVar, MutableSequence, cast | n | from typing import List, TypeVar, MutableSequence |
| 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(sequence: Sortable) -> Sortable: | t | def bubble(seq: Sortable) -> Sortable: |
| length = len(sequence) | | n = len(seq) |
| for i in range(length): | | for i in range(n): |
| for j in range(0, length - i - 1): | | for j in range(0, n - i - 1): |
| if sequence[j] > sequence[j + 1]: | | if seq[j] > seq[j + 1]: |
| sequence[j], sequence[j + 1] = (sequence[j + 1], sequence[j]) | | seq[j], seq[j + 1] = (seq[j + 1], seq[j]) |
| return sequence | | return seq |