For three items, you could use max
and min
to sort them:
a, b, c = 3, 1, 8
x = min(a, b, c) # Smallest of the three
z = max(a, b, c) # Largest of the three
y = (a + b + c) - (x + z) # Since you have two of the three, you can solve for
# the third
print(a, b, c)
print(x, y, z)
If you don't want to use a sorting algorithm but can use lists, you could just pop out the smallest item each time and store it in a new list:
numbers = [1, 8, 9, 6, 2, 3, 1, 4, 5]
output = []
while numbers:
smallest = min(numbers)
index = numbers.index(smallest)
output.append(numbers.pop(index))
print(output)
It's pretty inefficient, but it works.