sorted()
sorted(iterable, /, *, key=None, reverse=False)
Return a new list containing all items from the iterable in ascending order.
A custom key function can be supplied to customize the sort order, and the
reverse flag can be set to request the result in descending order.
# sorted() d = {0: 'z', 1: 'k', 2: 'l', 3: 'x'} print(sorted(d)) print(sorted(d, key=lambda x: d[x])) print(sorted(d, reverse=True))