Function Details: sorted

Description


Returns a new sorted list from the items in iterable.


Extended Description


The sorted() function returns a new sorted list from the items in the given iterable. It does not modify the original iterable. The function uses a stable sorting algorithm, meaning that when multiple records have the same key, their original order is preserved. The 'key' parameter specifies a function of one argument that is used to extract a comparison key from each element. The 'reverse' parameter, if set to True, sorts the list in descending order.


Read More about sorted from Python Documentation

Function Signature


sorted(iterable: Iterable, *, key: Optional[Callable] = None, reverse: bool = False) -> List

Module: builtins

Parameters



Parameter List


  • iterable: Iterable
  • key: Optional[Callable]
  • reverse: bool

Return


Returns a new sorted list containing all items from the iterable.


Return Type


List

Output

Explanation

These examples show sorting different types of iterables.