Using collection functions

Python offers a number of functions which work with any kind of collection. These include sorted(), max(), min(), and sum(). We also have some higher-order functions, map(), filter(), and the entire itertools module. We'll address additional higher-order functions in Chapter 8, More Advanced Functions.

The sorted() function returns a sorted list from a collection. It transforms the given collection into a list collection as part of the sorting process. If the collection doesn't define the proper iterator methods, it can't be easily sorted by using this function.

The max() and min() functions reduce a collection to a single value: either the largest or the smallest value in the collection. This reduction presumes that the ...

Get Python Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.