Python 3 Selection Sort Algorithm Script to Sort Number Array in Ascending or Descending Order Full Example Project For Beginners Welcome folks today in this blog post we will be sorting number array in ascending or descending order using selection sort algorithm in python. All the full source code of the application is shown below.

Get Started

In order to get started you need to make an app.py file and copy paste the following code

app.py

# Python program for implementation of Selection
# Sort
import sys
A = [64, 25, 12, 22, 11]

# Traverse through all array elements
for i in range(len(A)):

# Find the minimum element in remaining
# unsorted array
min_idx = i
for j in range(i+1, len(A)):
if A[min_idx] > A[j]:
min_idx = j

# Swap the found minimum element with
# the first element
A[i], A[min_idx] = A[min_idx], A[i]

# Driver code to test above
print ("Sorted array")
for i in range(len(A)):
print("%d" %A[i]),

Now if you execute the python file script by typing the below command as shown below

python app.py 