3. Advanced List Capabilities

“I’ve got a little list . . . ”

—Gilbert and Sullivan, The Mikado

To paraphrase the Lord High Executioner in The Mikado, we’ve got a little list. . . . Actually, in Python we,’ve got quite a few of them. One of the foundations of a strong programming language is the concept of arrays or lists—objects that hold potentially large numbers of other objects, all held together in a collection.

Python’s most basic collection class is the list, which does everything an array does in other languages, but much more. This chapter explores the basic, intermediate, and advanced features of Python lists.

3.1 Creating and Using Python Lists

Python has no data declarations. How, then, do you create collections such as a list? ...

Get Supercharged Python: Take Your Code to the Next Level, First Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.