Skip to main content

Lists

  • Chapter
  • First Online:
The Python Workbook

Part of the book series: Texts in Computer Science ((TCS))

  • 12k Accesses

Abstract

Lists help programmers manage larger amounts of data by allowing several (or even many) values to be stored in one variable. As a program executes it can transform a list (and the values within it) in numerous ways. Creatively applying these transformations, together with loops and decision making constructs, allows complex problems involving large amounts of data to be solved with a small number of variables. The specific list concepts explored in this chapter include:

  • Creating a new list,

  • Modifying a list by appending, inserting, updating and deleting elements,

  • Searching a list for a value,

  • Displaying some or all of the elements in a list, and

  • Writing a function that takes a list as an argument or returns a list as a result.

The chapter concludes with 26 exercises that allow the reader to use these concepts to solve a variety of problems.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 49.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD 54.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    The len function returns 0 if the list passed to it is empty.

  2. 2.

    Methods can also be applied to a list literal enclosed in square brackets using the same syntax, but there is rarely a need to do so.

  3. 3.

    A list can only be sorted if all of the elements in it can be compared to one another with the less than operator. The less than operator is defined for many Python types include integers, floating-point numbers, strings, and lists, among others.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Ben Stephenson .

Rights and permissions

Reprints and permissions

Copyright information

© 2019 Springer Nature Switzerland AG

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Stephenson, B. (2019). Lists. In: The Python Workbook. Texts in Computer Science. Springer, Cham. https://doi.org/10.1007/978-3-030-18873-3_5

Download citation

  • DOI: https://doi.org/10.1007/978-3-030-18873-3_5

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-030-18872-6

  • Online ISBN: 978-3-030-18873-3

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics