selection sort python

Solutions on MaxInterview for selection sort python by the best coders in the world

showing results for - "selection sort python"
Michele
24 Feb 2017
1def selection(s):
2    for i in range(0,len(s)-1):
3        p=0
4        mini=s[-1]
5        for j in range(i,len(s)):
6            if s[j]<=mini:
7                mini=s[j]
8                p=j
9        s[i],s[p]=s[p],s[i]
10print(s)
11selection([2,3,4,2,1,1,1,2])
Soumaya
03 Jun 2018
1def selection_sort(lst):
2    empty_lst = []
3    x = len(lst) - 1
4    while x>=0:
5        for i in range(len(lst)):
6            if lst[i] <= lst[0]:
7                lst[0],lst[i] = lst[i],lst[0]
8                # this part compares the number in first index and numbers after the first index.
9        g = lst.pop(0)
10        empty_lst.append(g)
11        x -= 1
12    return empty_lst
13    
14print(selection_sort([2,3,4,2,1,1,1,2]))
queries leading to this page
implement selection sort in pythonpython program to sort elements of a list using selection sortselection sort implementaiton python 27selection sort python programselection sort in sorted listselection sort algorithm for pythonalgorithm of selection sort in pythonselection sort in list pythonhow to selection sort in pythonselection sort in pythoncode for selection sortexamples of selection sorting pythonpython 2b selection sort number of operationsselection sort code pytonselection sort python codeselection sort pythselection sort python pythonhow to do selection sort in pythonwhen is selection sort bestselection sort algorithm in pythonselection sort in pythonnumber selection sort pythonselection sort algorithm pythonselect sort in pythonselection sort pythonselection sort on sorted listsort the list using selection sortselection sort using pytohnselection sort python explainedselection sorting pythonselection sort list basedpython selection sortingselection sort code in pythonpython selection sort 3fwrite a program to implement selection sort in pythonselection sort code pythonhow to use selection sort in pythonpython 2b selection sortimplementation of selection sort technique in pythonexample for selection sort pythonselection sort 29selection sort list what is selection sort in pythonselection sort on a sorted listselection sort epythonselection sort selection sort function pythonpython selection sort sort wsort using selection sort in pythonpython select sortpython selection sort programpython selection sortselection sort in pytonselection sort in python using listselection sorting in pythonselection sort python functionpython selection sort functionselection sort python 5cpython selection sort sort selection sort in place pythonpython program to sort a list of elements using selection sort algorithmpytho selection sortselection sort statements in pythonselect sort pythonselection sort using pythonselection sort in python and display at each stepsort selection pythonselection sort python