def selection_sort(alist):
    """
    Sorts a list using the selection sort algorithm.
    alist - The unsorted list.
    Examples
        selection_sort([4,7,8,3,2,9,1])
        # => [1,2,3,4,7,8,9]
    a selection sort looks for the smallest value as it makes a pass and, 
    after completing the pass, places it in the proper location
    Worst Case: O(n^2)
    Returns the sorted list.
    """
	
    # Traverse through all array elements
    for i in range(len(alist)):
        # assume that the first item of the unsorted segment is the smallest
        lowest_value_index = i
        # This loop iterates over the unsorted items
        for j in range(i + 1, len(alist)):
            if alist[j] < alist[lowest_value_index]:
                lowest_value_index = j
        # Swap values of the lowest unsorted element with the first unsorted
        # element
        alist[i], alist[lowest_value_index] = alist[lowest_value_index], alist[i]

    return alist