Login
You're viewing the code4lib.social public feed.
  • Nov 26, 2026, 9:12 PM
    retooted Trey Hunner 🐍

    Python Tip #330 (of 365):

    Pass a default to max and min to handle empty iterables.

    The max and min functions raise an exception when given nothing to compare:

    >>> numbers = []
    >>> max(numbers)
    Traceback (most recent call last):
    ...
    ValueError: max() iterable argument is empty

    🧵 (1/3)

    #Python #DailyPythonTip

    💬 1🔄 1⭐ 0