8.5. Idiom Sorted

8.5.1. Problem

>>> data = [3, 1, 2]
>>>
>>> result = data.copy()
>>> n = len(data)
>>> for i in range(n):
...     for j in range(0, n-i-1):
...         if result[j] > result[j+1]:
...             result[j], result[j+1] = result[j+1], result[j]
>>>
>>> result
[1, 2, 3]

8.5.2. Solution

>>> data = [3, 1, 2]
>>>
>>> result = sorted(data)
>>>
>>> result
[1, 2, 3]