删除Python 3.0中的列表推导 [英] removing list comprehensions in Python 3.0

查看:56
本文介绍了删除Python 3.0中的列表推导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

George Sakkis写道:

" Steven Bethard" < ST ************ @ gmail.com>写道:

最近拒绝了字典理解:
http://www.python.org/peps/pep-0274.html
当然,理由是dict理解不会让你获得很多在dict()构造函数加上一个生成器表达式,
例如:
dict((i,chr(65 + i))for i in range(4))



当然,但同样适用于列表理解:list(i * i for i in
xrange(10))。我估计差异是历史性的;列表推导
先于生成器表达式,所以它们不能被删除,至少不是在3.0之前。我想知道当向后兼容性的约束被取消时他们是否会/应该使用该语言。 IMO他们应该不是(TIOOWTDI,内置数据结构之间的一致性,而不是比设置或词典理解更有用),但
到那天还有很长的路要走。




我认为陪审团仍然在这个问题上:


* Alex Martelli希望删除列表理解。 [1]

* Robert Kern希望删除列表推导。 [2]

* Raymond Hettinger鼓励继续使用列表推理[3]

* Jeremy Bowers认为列表推导应该保留。 [4]


我只搜索了一些相对较新的clpy线程,所以有可能更多的是b $ b,但它看起来像最后的决定必须通过Guido的声明来制作



[1] http://groups-beta.google.com/group/comp。 lang.python / msg / f5613c00cb8c9539

[2] http://groups-beta.google.com/group/comp.lang.python/msg/b2cf0cd72d53fbe5

[ 3] http://groups-beta.google.com/group/comp.lang.python/msg/781dfab03701dd18

[4] http://groups-beta.google.com/group/ comp.lang.python / msg / 771a47d9eb24c863

解决方案

Steven Bethard schrieb:

我认为陪审团现在还在这个问题上:

* Alex Martelli希望删除列表理解。 [1]
* Robert Kern希望删除列表推导。 [2]
* Raymond Hettinger鼓励继续使用列表推导[3]
* Jeremy Bowers认为列表理解应该保持不变。 [4]

我只搜索了几个相对较新的clpy线程,所以有可能更多,但它在我看来最终的决定将不得不
来自Guido的声明。




嗯,我想提出一个更激进的建议:为什么不自由平方

来自负担代表名单?应该足够写
$ blockquote class =post_quotes>

list()



list()


免费后可以将它们用于其他目的,例如用可爱的[..]符号或其他

替换

丑陋的@ decorator角色重要功能没有人从不信任实现等待

正确的语法糖。超过这一轮的括号和列表可以被视为对LISP程序员的一种让步,因为决定消除函数式编程而被排斥的是来自Python的


功能。


Kay


Kay Schluehr写道:

好吧,我想提出一个更激进的提议:为什么不能免费代表列表的负担呢?它应该足够

list()



列表()




那么表达式列表(''foo'')是什么意思?它是否相当于[''foo'']
(如果是这样,你如何将字符串或其他的b / b $ b迭代转换为Py3k下的列表?),或者它是否相当于[''f'',''o'',

''o''],因为它在现在(并且是这样,是什么给出了?)?


列表推导比生成器理解更快,因为

迭代更小的序列。


George Sakkis wrote:

"Steven Bethard" <st************@gmail.com> wrote:

Dict comprehensions were recently rejected:
http://www.python.org/peps/pep-0274.html
The reason, of course, is that dict comprehensions don''t gain you
much at all over the dict() constructor plus a generator expression,
e.g.:
dict((i, chr(65+i)) for i in range(4))



Sure, but the same holds for list comprehensions: list(i*i for i in
xrange(10)). The difference is historic I guess; list comprehensions
preceded generator expressions and so they cannot be removed, at least
not before 3.0. I wonder if they will/should be in the language when
the constraint of backwards compatibility is lifted. IMO they should
not (TIOOWTDI, uniformity among builtin data structures, not
overwhelmingly more useful than set or dict comprehensions), but
there''s a long way till that day.



I think the jury''s still out on this one:

* Alex Martelli expects list comprehensions to be removed. [1]
* Robert Kern wants list comprehensions removed. [2]
* Raymond Hettinger encourages continued use of list comprehensions [3]
* Jeremy Bowers thinks list comprehensions should stay. [4]

I only searched a few relatively recent threads in c.l.py, so there are
probably more, but it looks to me like the final decision will have to
be made by a pronouncement from Guido.

[1]http://groups-beta.google.com/group/comp.lang.python/msg/f5613c00cb8c9539
[2]http://groups-beta.google.com/group/comp.lang.python/msg/b2cf0cd72d53fbe5
[3]http://groups-beta.google.com/group/comp.lang.python/msg/781dfab03701dd18
[4]http://groups-beta.google.com/group/comp.lang.python/msg/771a47d9eb24c863

解决方案

Steven Bethard schrieb:

I think the jury''s still out on this one:

* Alex Martelli expects list comprehensions to be removed. [1]
* Robert Kern wants list comprehensions removed. [2]
* Raymond Hettinger encourages continued use of list comprehensions [3]
* Jeremy Bowers thinks list comprehensions should stay. [4]

I only searched a few relatively recent threads in c.l.py, so there are
probably more, but it looks to me like the final decision will have to
be made by a pronouncement from Guido.



Well, I want to offer a more radical proposal: why not free squared
braces from the burden of representing lists at all? It should be
sufficient to write

list()


list()

After being free one can use them for other purposes e.g. replacing the
ugly @ decorator character by the lovely [ .. ] notation or other
important features no one never trusted to implement waiting for the
right syntax sugar. More than this round braces together with lists can
be considered as a concession to the LISP programmer who was repelled
from Python by the decision to eliminate functional programming
features.

Kay


Kay Schluehr wrote:

Well, I want to offer a more radical proposal: why not free squared
braces from the burden of representing lists at all? It should be
sufficient to write

list()



list()



So then what would the expression list(''foo'') mean? Would it be
equivalent to [''foo''] (if so, how would you convert a string or other
iterable to a list under Py3k?), or would it be equivalent to [''f'', ''o'',
''o''] as it is in now (and is so, what gives?)?


List comprehensions are faster than generator comprehensions for
iterating over smaller sequences.


这篇关于删除Python 3.0中的列表推导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆