跳转至

3.19. 列表

3.19. Lists

在基本数据结构的讨论中,我们使用了 Python 列表来实现所介绍的抽象数据类型。列表是一种强大而简单的集合机制,它为程序员提供了多种操作。然而,并不是所有编程语言都包含列表集合。在这些情况下,列表的概念必须由程序员实现。

列表 是一组项目的集合,其中每个项目相对于其他项目具有相对位置。更具体地说,我们将这种类型的列表称为 无序列表。我们可以将列表视为具有第一个项目、第二个项目、第三个项目,依此类推。我们也可以参考列表的开始(第一个项目)或结束(最后一个项目)。为了简化起见,我们将假设列表不能包含重复项目。

例如,整数集合 54、26、93、17、77 和 31 可能代表一个简单的无序考试成绩列表。注意,我们将它们写成用逗号分隔的值,这是一种常见的显示列表结构的方式。当然,Python 会将此列表显示为 [54, 26, 93, 17, 77, 31]

Throughout the discussion of basic data structures, we have used Python lists to implement the abstract data types presented. The list is a powerful, yet simple collection mechanism that provides the programmer with a wide variety of operations. However, not all programming languages include a list collection. In these cases, the notion of a list must be implemented by the programmer.

A list is a collection of items where each item holds a relative position with respect to the others. More specifically, we will refer to this type of list as an unordered list. We can consider the list as having a first item, a second item, a third item, and so on. We can also refer to the beginning of the list (the first item) or the end of the list (the last item). For simplicity we will assume that lists cannot contain duplicate items.

For example, the collection of integers 54, 26, 93, 17, 77, and 31 might represent a simple unordered list of exam scores. Note that we have written them as comma-delimited values, a common way of showing the list structure. Of course, Python would show this list as [54, 26, 93, 17, 77, 31].


最后更新: 2024年9月12日
创建日期: 2024年9月9日