This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
def selection_sort(arr): | |
for idx in range(len(arr)): | |
min_idx = idx | |
for jdx in range(idx + 1, len(arr)): | |
if arr[min_idx] > arr[jdx]: | |
min_idx = jdx | |
arr[idx], arr[min_idx] = arr[min_idx], arr[idx] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_zeroes(lst: list) -> list: | |
"""Удаление нулей из списка с сохранением относительного порядка элементов. | |
Скорость работы - линейна. | |
Дополнительная память не используется. | |
>>> remove_zeroes([]) | |
[] | |
>>> remove_zeroes([0]) | |
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def symmetric_difference(lst1: list, lst2: list) -> list: | |
"""Возвращает элементы, которые есть в первом списке, но нет в обоих. | |
Скорость работы и используемая дополнительная память - линейна. | |
>>> symmetric_difference([], []) | |
[] | |
>>> symmetric_difference([], [1, 2]) | |
[] | |
>>> symmetric_difference([1, 2, 3], []) |