为什么 Python 中的列表理解如此称呼?
我知道 Python 不是第一个具有列表理解的语言。 我只是对这个名字的历史感兴趣。
我特别感兴趣的是为什么它被称为理解
为什么列表理解在Python中如此称呼?
I know Python is not the first language to have list comprehension.
I'm just interested in the history of the name.
I'm particularly interested in why it's called comprehension
Why is list comprehension called so in Python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
的概念
该名称来自集合理解 理解 此处用于表示完整包含或完整描述。集合推导式是对集合的(通常是简短的)完整描述,而不是详尽的(可能是无限的)枚举。
The name comes from the concept of a set-comprehension
Comprehension is used here to mean complete inclusion or complete description. A set-comprehension is a (usually short) complete description of a set, not an exhaustive (and possibly infinite) enumeration.
“理解”过去不仅意味着“理解”,而且意味着逻辑上的“包容”。 《牛津英语词典》有以下内容:“I.4.逻辑概念或概念中所包含的属性的总和;内涵”作为第一个定义“包含,包含”下的第四个子定义。如果得知这种用法从此进入数学史,我不会感到惊讶。在列表或集合理解中,程序员不是明确给出列表或集合的元素,而是用表达式描述他们所理解的内容(在“包含”意义上)。
"Comprehension" used to mean not only "understanding," but "inclusion" in logic. Oxford English Dictionary has the following: "I.4. Logic The sum of the attributes comprehended in a notion or concept; intension" as the fourth subdefinition under the first definition, "Inclusion, comprising." I wouldn't be surprised to learn that the usage passed into the history of mathematics through there. In a list or set comprehension, instead of giving the elements of the list or set explicitly, the programmer is describing what they comprehend (in the "include" sense) with an expression.
https://www.merriam-webster.com/dictionary/comprehend
https://www.merriam-webster.com/dictionary/comprehend
维基百科页面的历史部分讨论了它的来源。
List_compressive#History
The history section of the wikipedia page discusses a little on where it came from.
List_comprehension#History
因为它是描述序列(数学和其他语言中的集合,以及 Python 中的列表/序列)的一种非常全面的方式。
Because it's a very comprehensive way to describe a sequence (a set in math and other languages, and a list/sequence in Python).
我的理解是:综合就是指做某件事的方法有很多。所以这意味着你不仅可以用一种特定的方式来做某件事,还有很多其他的方式来做这件事。例如,在 Python 中,列表理解意味着您可以直接创建一个新列表,或者基于现有列表的值来创建一个新列表,以满足您定义的条件。
As I understand it: Comprehensive means it includes many ways to do something. So it means you can not only do something in one particular way that you have done it, there are many other ways to do it. So in Python, for example, List Comprehension means you can create a new List either directly, or based on values of an existing list, meeting your defined conditions.