From e1805c9fb5e34ada8142ea36685e0655d4c24375 Mon Sep 17 00:00:00 2001 From: marina <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Wed, 2 Aug 2023 20:52:30 -0700 Subject: [PATCH] Create seletction_sort.py --- sorting/seletction_sort.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 sorting/seletction_sort.py diff --git a/sorting/seletction_sort.py b/sorting/seletction_sort.py new file mode 100644 index 0000000..ccd601d --- /dev/null +++ b/sorting/seletction_sort.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# author: bt3gl + + +def selection_sort(lst): + + for i in range(len(lst)): + min_index = i + for j in range(i + 1, len(lst)): + if lst[j] < lst[min_index]: + min_index = j + + lst[min_index], lst[i] = lst[i], lst[min_index]