Skip to ContentGo to accessibility page
Introduction to Python Programming

9.3 Common list operations

Introduction to Python Programming9.3 Common list operations

9.3 Common list operations

Learning objectives

By the end of this section you should be able to

  • Use built-in functions max(), min(), and sum().
  • Demonstrate how to copy a list.

Using built-in operations

The max() function called on a list returns the largest element in the list. The min() function called on a list returns the smallest element in the list. The max() and min() functions work for lists as long as elements within the list are comparable.

The sum() function called on a list of numbers returns the sum of all elements in the list.

Example 9.3

Common list operations

    """Common list operations."""

    # Set up a list of number
    snum_list = [28, 92, 17, 3, -5, 999, 1]

    # Set up a list of words
    city_list = ["New York", "Missoula", "Chicago", "Bozeman", 
    "Birmingham", "Austin", "Sacramento"]

    # Usage of the max() funtion
    print(max(num_list))

    # max() function works for strings as well
    print(max(city_list))
    
    # Usage of the min() funtion which also works for strings
    print(min(num_list))

    print(min(city_list))

    # sum() only works for a list of numbers
    print(sum(num_list))

The above code's output is:

    999
    Sacramento
    -5
    Austin
    1135

Concepts in Practice

List operations

1.
What is the correct way to get the minimum of a list named nums_list?
  1. min(nums_list)
  2. nums_list.min()
  3. minimum(nums_list)
2.
What is the minimum of the following list?
["Lollapalooza", "Coachella", "Newport Jazz festival", "Hardly Strictly Bluegrass", "Austin City Limits"]
  1. Coachella
  2. Austin City Limits
  3. The minimum doesn't exist.
3.
What value does the function call return?
sum([1.2, 2.1, 3.2, 5.9])
  1. sum() only works for integers.
  2. 11
  3. 12.4

Copying a list

The copy() method is used to create a copy of a list.

Checkpoint

Concepts in Practice

Copying a list

4.
What is the output of the following code?
my_list = [1, 2, 3]
list2 = my_list
list2[0] = 13
print(sum(my_list))
  1. 6
  2. 13
  3. 18
5.
What is the output of the following code?
my_list = [1, 2, 3]
list2 = my_list.copy()
list2[0] = 13
print(max(my_list))
  1. 3
  2. 13
  3. 18
6.
What is the output of the following code?
my_list = ["Cat", "Dog", "Hamster"]
list2 = my_list
list2[2] = "Pigeon"
print(sum(my_list))
  1. CatDogPigeon
  2. Error

Try It

Copy

Make a copy of word_list called wisdom. Sort the list called wisdom. Create a sentence using the words in each list and print those sentences (no need to add periods at the end of the sentences).

Citation/Attribution
Reuse and redistribution of this content in digital or print format:
  • This book may not be used in the training of large language models or otherwise be ingested into large language models or generative AI offerings without OpenStax's prior written permission.
  • This book uses the Creative Commons Attribution-NonCommercial-ShareAlike License, which means that you can reuse and modify the material only for noncommercial purposes, must attribute OpenStax, and must distribute any derivative works under the same license.
  • Any commercial printing of this textbook, including using a local or custom printer, must be approved by OpenStax, and proper citation provided.
  • OpenStax-copyrighted images, activities, assessments, and similar components of this book are subject to the same licensing – CC-BY-NC-SA. They can be used for noncommercial purposes with attribution. Commercial use requires permission.
  • Permission requests: Anyone who intends to incorporate this content (including text, images, and other components) into large language models, use it in AI offerings, use it commercially (including in print), and/or has questions about another use case is welcome to complete our reuse request form.
Attribution information
  • If you are redistributing all or part of this book in a noncommercial print format, then you must include on every physical page the following attribution:

    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction

  • If you are redistributing all or part of this book in a noncommercial digital format, then for every page that includes OpenStax content, you must license the derivative work under the same CC-BY-NC-SA license as the original, and include on every digital page view the following attribution:

    Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction

Citation information

The information below includes the information needed to generate citations in most major styles (APA, MLA, etc.); you must reformat and organize the information as needed to fit the requirements of the style. Use the information below to generate a citation. We recommend using a citation tool such as this one.

© Apr 23, 2026 OpenStax. Textbook content produced by OpenStax is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike License. The OpenStax name, OpenStax logo, OpenStax book covers, OpenStax CNX name, and OpenStax CNX logo, and Rice University name, and Rice University logo trademarks, or wordmarks are not subject to the Creative Commons license and may not be reproduced without the prior and express written consent of Rice University.

This book utilizes the OpenStax Python Code Runner. The code runner is developed by Wiley and is All Rights Reserved.