Python program for Selection Sort Algorithm

[5946 views]




In this article, you will learn how to write simple Selection Sort Algorithm in Python.

Selection Sort program in Python

Code:

def selectionsort(alist): for i in range(len(alist)): smallest_no = min(alist[i:]) index = alist.index(smallest_no) alist[i], alist[index] = smallest_no, alist[i] i = i + 1 return alist if __name__ == '__main__': num = int(raw_input("Enter total numbers which you are going to entered ")) nlist = [] while num > 0: no = raw_input("Enter the number") nlist.append(no) num = num - 1 result = selectionsort(nlist) print result

Output:

Enter total numbers which you are going to entered 5 Enter the number8 Enter the number3 Enter the number4 Enter the number1 Enter the number2 ['1', '2', '3', '4', '8']
                 





Comments








Search
Need any Help?


Hot Deals ends in





Earn Money While You Sleep. Join Now to avail Exclusive Bonus




Technical Quiz:



Search Tags

    Write a Selection Sort program in Python

    Program for Selection Sort Algorithm in Python