Chapter 2. An Array of Sequences
As you may have noticed, several of the operations mentioned work equally for texts, lists and tables. Texts, lists and tables together are called ‘trains’. [...] The
FOR
command also works generically on trains.Leo Geurts, Lambert Meertens, and Steven Pembertonm, ABC Programmer’s Handbook1
Before creating Python, Guido was a contributor to the ABC language—a 10-year research project to design a programming environment for beginners. ABC introduced many ideas we now consider “Pythonic”: generic operations on different types of sequences, built-in tuple and mapping types, structure by indentation, strong typing without variable declarations, and more. It’s no accident that Python is so user-friendly.
Python inherited from ABC the uniform handling of sequences. Strings, lists, byte sequences, arrays, XML elements, and database results share a rich set of common operations, including iteration, slicing, sorting, and concatenation.
Understanding the variety of sequences available in Python saves us from reinventing the wheel, and their common interface inspires us to create APIs that properly support and leverage existing and future sequence types.
Most of the discussion in this chapter applies to sequences in general,
from the familiar list
to the str
and bytes
types added in Python 3.
Specific topics on lists, tuples, arrays, and queues are also covered here,
but the specifics of Unicode strings and byte sequences appear in Chapter 4. Also, the ...
Get Fluent Python, 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.