Using Python's min() and max() (Overview)

Python’s built-in min() and max() functions come in handy when you need to find the smallest and largest values in an iterable or in a series of regular arguments. Even though these might seem like fairly basic computations, they turn out to have many interesting use cases in real-world programing. You’ll try out some of those use cases here.

In this video course, you’ll learn how to:

  • Use Python’s min() and max() to find smallest and largest values in your data
  • Call min() and max() with a single iterable or with any number of regular arguments
  • Use min() and max() with strings and dictionaries
  • Tweak the behavior of min() and max() with the key and default arguments
  • Use comprehensions and generator expressions as arguments to min() and max()

Once you have this knowledge under your belt, then you’ll be prepared to write a bunch of practical examples that will showcase the usefulness of min() and max(). Finally, you’ll code your own versions of min() and max() in pure Python, which can help you understand how these functions work internally.

To get the most out of this video course, you should have some previous knowledge of Python programming, including topics like for loops, functions, list comprehensions, and generator expressions.

Download

Sample Code (.zip)

914 bytes
Download

Course Slides (.pdf)

5.9 MB

00:00 Python’s min() and max().

00:03 Python’s built-in min() and max() functions come in handy when you need to find the smallest and largest values in an iterable or series of regular arguments.

00:13 Even though these might seem like fairly basic computations, they turn out to have many interesting use cases in real-world programming. You’ll try out some of those use cases here in this course.

00:25 You’ll learn how to use Python’s min() and max() to find the smallest and largest values in your data, call min() and max() with a single iterable or with any number of regular arguments, use min() and max() with strings and dictionaries, tweak the behavior of min() and max() with the key and default arguments, use comprehensions and generator expressions as arguments to min() and max(), look at some practical examples showcasing the usefulness of min() and max(), and code your own versions of min() and max() in pure Python, which will help you understand how these functions work internally.

01:01 To get the most out of this course, you should have some previous knowledge of Python programming, including topics such as for loops, functions, list comprehensions, and generator expressions.

01:13 Any code that you see running in the REPL will be using the bpython interpreter. This is a replacement Python interpreter that offers a number of enhancements, including code highlighting and suggestions.

01:23 But any code you see running on-screen will work in the Python REPL, which is typically accessed by typing python or python3 at your terminal or command-line prompt. So now you know what’s going to be covered, let’s get started.

Become a Member to join the conversation.