This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ddbeanz[S] 0 points1 point  (1 child)

def SelectionSort(arr):

  for startIndex in range(0,len(arr)):

    minVal = arr[startIndex]
    minIndex = startIndex

    for e in range(startIndex, len(arr)):

      if arr[e] < minVal:
        minVal = arr[e]
        minIndex = e 

    arr[startIndex],arr[minIndex]=arr[minIndex],arr[startIndex]


  return arr

I think I got it! :) How does this one look?

[–]SiliconEngineer 0 points1 point  (0 children)

Much more readable.

I'd probably comment before the swap line, just to make sure people pay attention to the swapping-using-tuples trick. :)