为什么Python 2.6没有设置文字和理解或词典理解?

时间:2021-01-10 09:56:40

Python 2.6 was basically a stepping stone to make converting to Python 3 easier. A lot of the features destined for Python 3 were implemented in 2.6 if they didn't break backward compatibility with syntax and the class libs.

Python 2.6基本上是一个让转换为Python 3更容易的垫脚石。如果Python没有破坏与语法和类库的向后兼容性,那么很多用于Python 3的功能都在2.6中实现。

Why weren't set literals ({1, 2, 3}), set comprehensions ({v for v in l}), or dict comprehensions ({k: v for k, v in d}) among them? In particular dict comprehensions would have been a great boon... I find myself using the considerably uglier dict([(k, v) for k, v in d]) an awful lot lately.

为什么没有设置文字({1,2,3}),设置理解({v for v in l}),或者dict comprehensions({k:v for k,v in d})?特别是字典理解本来是一个很大的好处......我发现自己使用了相当丑陋的字典([(k,v)for k,v in d])最近很多。

Is there something obvious I'm missing, or was this just a feature that didn't make the cut?

有没有明显的东西我缺少,或者这只是一个没有削减的功能?

2 个解决方案

#1


19  

It wasn't done because nobody took the time to do it. There are bugs opened for months, and no one commented on them:

它没有完成,因为没有人花时间去做。几个月都有漏洞,没有人对它们发表评论:

So it wasn't important enough for anybody to care, probably.

因此,对任何人来说,这可能并不重要。

#2


10  

All these are syntax/grammar changes. Such changes are traditionally introduced first in a Python x.y version with a from __future__ import … statement, and implemented at least on Python x.(y+1) version. Such a transition hasn't happened yet for these changes.

所有这些都是语法/语法的变化。传统上,这些更改首先在Python x.y版本中引入,其中包含from __future__ import ...语句,并且至少在Python x。(y + 1)版本上实现。对于这些变化,这种转变尚未发生。

Technically, I've answered your "why".

从技术上讲,我已经回答了你的“为什么”。

Now, if you meant, “why didn't anyone take the time to suggest, support and implement something that I would like to have in 2.x also, even if they don't know about it since I never tried to suggest/support backporting those syntax enhancements in either comp.lang.python or Python-Dev and I never tried to even read the PEPs?”, then the answer lies in you too, and you can offer an answer yourself.

现在,如果你的意思是,“为什么没有人花时间建议,支持和实现我想在2.x中拥有的东西,即使他们不知道它,因为我从未试图建议/支持在comp.lang.python或Python-Dev中反向移植那些语法增强,我从未尝试过阅读PEP?“,那么答案也在于你,你可以自己提供答案。

HTH

BTW, you shouldn't use the dict([(k,v) for k,v in d]) form, but the dict((k,v) for k,v in d). More efficient. Why create an intermediate list?

顺便说一下,你不应该使用dict([(k,v)代表k,v代表d])形式,但dict((k,v)代表k,v代表d)。更高效。为什么要创建中间列表?

#1


19  

It wasn't done because nobody took the time to do it. There are bugs opened for months, and no one commented on them:

它没有完成,因为没有人花时间去做。几个月都有漏洞,没有人对它们发表评论:

So it wasn't important enough for anybody to care, probably.

因此,对任何人来说,这可能并不重要。

#2


10  

All these are syntax/grammar changes. Such changes are traditionally introduced first in a Python x.y version with a from __future__ import … statement, and implemented at least on Python x.(y+1) version. Such a transition hasn't happened yet for these changes.

所有这些都是语法/语法的变化。传统上,这些更改首先在Python x.y版本中引入,其中包含from __future__ import ...语句,并且至少在Python x。(y + 1)版本上实现。对于这些变化,这种转变尚未发生。

Technically, I've answered your "why".

从技术上讲,我已经回答了你的“为什么”。

Now, if you meant, “why didn't anyone take the time to suggest, support and implement something that I would like to have in 2.x also, even if they don't know about it since I never tried to suggest/support backporting those syntax enhancements in either comp.lang.python or Python-Dev and I never tried to even read the PEPs?”, then the answer lies in you too, and you can offer an answer yourself.

现在,如果你的意思是,“为什么没有人花时间建议,支持和实现我想在2.x中拥有的东西,即使他们不知道它,因为我从未试图建议/支持在comp.lang.python或Python-Dev中反向移植那些语法增强,我从未尝试过阅读PEP?“,那么答案也在于你,你可以自己提供答案。

HTH

BTW, you shouldn't use the dict([(k,v) for k,v in d]) form, but the dict((k,v) for k,v in d). More efficient. Why create an intermediate list?

顺便说一下,你不应该使用dict([(k,v)代表k,v代表d])形式,但dict((k,v)代表k,v代表d)。更高效。为什么要创建中间列表?