Skip to content

Instantly share code, notes, and snippets.

@ioanzicu
Created August 5, 2022 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioanzicu/6bcc4d4e58cf8c53265e095b4cd2dd05 to your computer and use it in GitHub Desktop.
Save ioanzicu/6bcc4d4e58cf8c53265e095b4cd2dd05 to your computer and use it in GitHub Desktop.
Selections sort in Python 3 - classic implementation.
def selection_sort(nums):
for i in range(len(nums)):
minim_index = i
for j in range(i + 1, len(nums)):
if nums[minim_index] > nums[j]:
minim = nums[j]
minim_index = j
nums[i], nums[minim_index] = nums[minim_index], nums[i]
return nums
nums = [1, 22, 3, 43, 5]
res = selection_sort(nums)
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment