The `sorted()` function takes in an iterable and a couple of optional arguments.
In this example, you pass in a Python list and sort it from smallest to largest.
Then you set the optional `reverse` argument to True and sort from largest to smallest! ππ₯
The `sorted()` function also takes an optional `key` parameter. This parameter is a function that is used to modify the sorting behavior.
In this example, you use `str.lower()` to sort the words of a sentence. It will compare all the words in lowercase while sorting.
This last example shows how to sort a list of tuples. You can use the optional `key` parameter to sort by different items within the tuple using a `lambda`
Python dataclasses were added in 3.7. This module provides a decorator and functions for automatically adding generated special methods such as __init__() and __repr__() to user-defined classes.
Python dataclasses were added in 3.7. This module provides a decorator and functions for automatically adding generated special methods such as __init__() and __repr__() to user-defined classes.