def median(x):
    """Find the median of a sample by sorting the sample and then returning the middle element."""
    x = sorted(x)  # Sort the sample
    n = len(x)
    middle = n // 2
    if n % 2 == 0:
        # If there's an even number of elements, the median is an average of the two middle values
        return 0.5 * (x[middle - 1] + x[middle])
    else:
        # If there's an odd number of elements, the median is the middle element
        return x[middle]