Operations on Lists

Functions That Python Provides, and Operations on Strings, introduced a few of Python’s built-in functions. Some of these, such as len, can be applied to lists, as well as others we haven’t seen before. (See the following table.)

Table 9. List Functions

Function

Description

len(L)

Returns the number of items in list L

max(L)

Returns the maximum value in list L

min(L)

Returns the minimum value in list L

sum(L)

Returns the sum of the values in list L

sorted(L)

Returns a copy of list L where the items are in order from smallest to largest (This does not mutate L.)

Here are some examples. The half-life of a radioactive substance is the time taken for half of it to decay. After twice this ...

Get Practical Programming, 2nd Edition 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.