TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Python “lists” are not lists. A history

10 点作者 daGrevis超过 11 年前

8 条评论

mwhooker超过 11 年前
this is useless. In the python interface they are obviously lists. Is the author arguing that cpython implements them as C arrays? I don&#x27;t know because the terms weren&#x27;t defined.<p>If the author believes clarity will arise from pedantry, maybe he should start with wikipedia<p>&gt; In computer science, a list or sequence is an abstract data type that implements a finite ordered collection of values, where the same value may occur more than once.<p><a href="https://en.wikipedia.org/wiki/List_(abstract_data_type)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;List_(abstract_data_type)</a>
评论 #6860452 未加载
评论 #6860463 未加载
评论 #6860440 未加载
axiak超过 11 年前
A list is called a list in python for the same reason the term dictionary is used -- these are the high level concepts for abstract types. The specific implementation details aren&#x27;t too important, as often times you just want &quot;the fastest in general&quot; which python does fairly well given the constraints.<p>As an example, a dictionary is implemented by a hash map, but after investigation, CPython may very well decide that any dictionary smaller than N is implemented as a constant table lookup. It wouldn&#x27;t be renamed to TableLookupToHashMap. That would be silly.
Shish2k超过 11 年前
&gt; a list is a list [...] these are well defined computer science terms<p>&quot;list&quot; is a CS term? I know that &quot;(doubly|singly) linked list&quot; is a CS term, but have never heard anyone mention list by itself (unless context made it obvious that they mean &quot;linked list&quot; - but then I&#x27;ve also seen people use the word &quot;list&quot; when the context made it obvious that they underlying data structure was an array)<p>tl;dr: Python &quot;lists&quot; are not &quot;linked lists&quot;. But nobody said they were.
fdej超过 11 年前
I don&#x27;t see any problem with using &quot;list&quot; to refer to any data structure that is functionally equivalent to a list, regardless of implementation. This is hardly unique to Python: Mathematica&#x27;s List type (despite the Lisp heritage) is also really an array.<p>You could easily imagine the implementation being changed to something else (say a VList or unrolled linked list) if someone did some benchmarking and it turned out that it made Python programs 5% faster on average. Then the name &quot;array&quot; would no longer be accurate, and neither would &quot;list&quot; in the narrow, pedantic sense. So using the term &quot;list&quot; in a more abstract sense is perfectly reasonable.<p>The term &quot;list&quot; also has some (tiny) advantages: it&#x27;s shorter than &quot;array&quot; or &quot;vector&quot;, and it&#x27;s one less technical term for people learning programming (as I understand, this was one of Guido&#x27;s design goals).<p>If we&#x27;re going to talk about inaccurately named data types, let&#x27;s start with the ubiquitous use of &quot;integer&quot; to refer to bastardized integers modulo 2^32...
caisah超过 11 年前
Contrary to people&#x27;s opinion on this topic I agree to what the author has to say. He states his point in the introduction: &quot; they use terms imprecisely, they write like journalists not scientists&quot;.<p>This is a classic example on how we popularize misuse of certain words&#x2F;concepts. And Wiki isn&#x27;t always the best source when we argue on these subjects. I have nothing against anybody using words as they like. But the more we use appropriate terms, the more we can make ourselves better understood.<p>Most people don&#x27;t care about semantics but there are some that do. And those who are actively participating in a filed like the scientific one should try to be as clear as possible. Science requires rigor.
seanhandley超过 11 年前
Newbie Python question: What does a Python List do that a Ruby Array doesn&#x27;t do? Regardless of the implementation, this is a question of the abstract behaviour of a data structure. If a Python List is functionally equivalent to an Array (which is a sequence) then why coin it as a &quot;List&quot; ?
评论 #6860520 未加载
jrockway超过 11 年前
It is weird to call it a list and then use indexing operations on it. But if you just cons stuff onto the front and iterate over the whole structure from time to time, it&#x27;s perfectly fine to call it one, since if it were a linked list, you wouldn&#x27;t be misusing the structure.
ozh超过 11 年前
§