sorted()
Returns a new sorted list from an iterable. Does not modify the original.
Syntax
python
sorted(iterable, key=None, reverse=False)Example
python
nums = [3, 1, 4, 1, 5, 9]
print(sorted(nums)) # [1, 1, 3, 4, 5, 9]
print(sorted(nums, reverse=True)) # [9, 5, 4, 3, 1, 1]