Python program for Selection Sort Algorithm

[2930 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']
        

Don't Understand Algorithm and Flowchart? Learn quickly using our Expert's Notes



Want to get in-depth understanding of Algorithms?


Are You Good enough in Algorithms? Test it now?


Comments



Search
Recommended Deals End in










Java Interview Questions For Beginner Notes
Quiz for Learners
Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Search Tags

    Write a Selection Sort program in Python

    Program for Selection Sort Algorithm in Python