Python Program to Implement Selection Sort


In this program, we will implement selection sort algorithm

  1. #Python program to implement Selection sort
  2. def selection_sort(a):
  3. for i in range(0, len(a) - 1):
  4. first = i
  5. for j in range(i + 1, len(a)):
  6. if a[j] < a[first]:
  7. first = j
  8. a[i], a[first] = a[first], a[i]
  9. a = input('Enter list elements: ').split()
  10. a = [int(x) for x in a]
  11. selection_sort(a)
  12. print('Sorted list: ', end='')
  13. print(a)

Output

Output!