# Title: Selection sort
# Heading: Python Program for Selection Sort
# Level: beginner
# Tags: sorting, selection sort, minimum, swap, list
# Time: O(n²)
# Space: O(1)
# About: Sorts a list by finding the smallest item left and swapping it to the front of the unsorted part, one place at a time.

def selection_sort(items):
    """Sort items in place, from smallest to largest."""
    n = len(items)
    for i in range(n - 1):
        smallest = i  # index of the smallest item found so far
        for j in range(i + 1, n):
            if items[j] < items[smallest]:
                smallest = j
        items[i], items[smallest] = items[smallest], items[i]


numbers = [38, 27, 43, 3, 9, 82, 10]
print("Before:", numbers)
selection_sort(numbers)
print("After: ", numbers)
