sorted returns a new list with an iterable’s items in sorted order. Unlike list.sort(), it leaves the original list unchanged. section 28.2
Keep the original list
kid_ages = [2, 1, 4] sorted_ages = sorted(kid_ages) sorted_ages # [1, 2, 4] kid_ages # [2, 1, 4] The result goes into sorted_ages, while kid_ages stays in its original order. section 28.2
Choose the operation that matches your goal:
- Use sorted(values) when you need a sorted copy. section 28.2
- Use values.sort() when changing the existing list is acceptable. section 28.2




