Skip to Main Content
High Performance Python, 2nd Edition
book

High Performance Python, 2nd Edition

by Micha Gorelick, Ian Ozsvald
April 2020
Intermediate to advanced content levelIntermediate to advanced
468 pages
12h 52m
English
O'Reilly Media, Inc.
Book available
Content preview from High Performance Python, 2nd Edition

Chapter 3. Lists and Tuples

One of the most important things in writing efficient programs is understanding the guarantees of the data structures you use. In fact, a large part of performant programming is knowing what questions you are trying to ask of your data and picking a data structure that can answer these questions quickly. In this chapter we will talk about the kinds of questions that lists and tuples can answer quickly, and how they do it.

Lists and tuples are a class of data structures called arrays. An array is a flat list of data with some intrinsic ordering. Usually in these sorts of data structures, the relative ordering of the elements is as important as the elements themselves! In addition, this a priori knowledge of the ordering is incredibly valuable: by knowing that data in our array is at a specific position, we can retrieve it in O(1)!1 There are also many ways to implement arrays, and each solution has its own useful features and guarantees. This is why in Python we have two types of arrays: lists and tuples. Lists are dynamic arrays that let us modify and resize the data we are storing, while tuples are static arrays whose contents are fixed and ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Deep Learning with Python, Second Edition

Deep Learning with Python, Second Edition

Francois Chollet
Python Cookbook, 3rd Edition

Python Cookbook, 3rd Edition

David Beazley, Brian K. Jones
Python in a Nutshell, 4th Edition

Python in a Nutshell, 4th Edition

Alex Martelli, Anna Martelli Ravenscroft, Steve Holden, Paul McGuire

Publisher Resources

ISBN: 9781492055013Errata PageSupplemental Content