Return a new list containing all items from iterable in sorted order. key can compute comparison keys; reverse=True sorts descending while keeping equal-key items stable.
Syntax
sorted(iterable, /, *, key=None, reverse=False)Parameters
| Name | Description |
|---|---|
iterableString | list | tuple | dict | set | Iterable input. Dictionaries sort keys. Required · Positional only No default |
keyCallable? | One-argument callable used to compute comparison keys. Optional · Keyword only Default: None |
reverseBoolean | Sort descending when True. Optional · Keyword only Default: False |
Returns
Example
values = sorted([3, 1, 2])
text(str(values))