减少被删除? [英] reduce to be removed?

查看:48
本文介绍了减少被删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据维基百科上的以下页面:
http://en.wikipedia.org/wiki/Python_...re_development

reduce将在python 3.0中删除。它谈到了一个

积累循环;我不知道那是什么意思。那么,


===============================
< blockquote class =post_quotes>


>> x =



[[1,2,3],

[4,5,6],

[7,8,9]]


>> reduce(lambda a,b:a + b,x,[])



[1,2,3,4,5,6,7,8,9]

=== ============================

什么是积累循环,以及如何我会转换这段代码,所以它与未来的3.0兼容吗(最好用一个简短的甜蜜表达

,我可以嵌入列表理解中)?


什么是积累循环,以及如何转换此代码它是* b $ b与未来兼容3.0



Python 3.0的版本很远,没有人知道它是怎么回事去看看
。试图在这个时候兼容未来是一个主要的浪费

的时间和(并不像重新开放那样浪费另一个旧的让我们的

做一些毫无意义的改变语言线程,但差不多。


你肯定必须有更好的时间来处理你的时间吗?


< / F>


Fredrik Lundh写道:


Dustan写道:
< blockquote class =post_quotes>
什么是累积循环,我将如何转换此代码,以便它与未来3.0
兼容



Python 3.0的版本很远,没有人知道它是怎么回事的。试图在这个时候兼容未来是一个主要的浪费

的时间和(并不像重新开放那样浪费另一个旧的让我们的

做一些毫无意义的改变语言线程,但差不多。


你肯定必须有更好的时间来处理你的时间吗?


< / F>



我们总是很高兴知道有这样善良的人准备好帮助这个小组。无论如何,我想出了一种方法来获取内置的

函数''sum''以便我可以工作:

sum([[1,2,3], [4,5,6],[7,8,9]],[])


在不相关的注释中,任何人都可以在
$ b上解释这种不可预测的行为$ b IDLE?我发誓我从未打过ctrl-c ......

==============================


>> help(sum)



模块中内置函数求和的帮助__builtin __:


sum(...)

sum(sequence,start = 0)-value


返回一系列数字(非字符串)加上

值的总和

参数''start''。当序列为空时,返回开始。

Traceback(最近一次调用最后一次):

文件"< pyshell#0>",第1行,in< ;模块>

帮助(总和)

文件C:\ Piy25 \ lib\site.py,第346行,在__call__

返回pydoc.help(* args,** kwds)

文件C:\Python25 \lib\pydoc.py,第1642行,__ call __

self.help(请求)

文件C:\Python25 \ lib \ pydoc.py,第1687行,在帮助中

self.output.write(''\ n'')

文件" C:\Python25 \lib \idlelib \ PyShell.py",第1246行,写入

self.shell.write(s,self.tags)

文件" C:\Python25 \lib \idlelib \ PyShell.py",第1235行,写中

筹码KeyboardInterrupt

KeyboardInterrupt

===================== =========




Dustan写道:


根据维基百科上的以下页面:
http://en.wikipedia.org/wiki/Python_...re_development

reduce将被删除python 3.0。它谈到了一个

积累循环;我不知道那是什么意思。那么,


===============================
< blockquote class =post_quotes>


> x =



[[1,2,3],

[4,5,6],

[7,8,9]]


> reduce(lambda a,b:a + b,x,[])



[1,2,3,4 ,5,6,7,8,9]

===============================


什么是累积循环,我将如何转换此代码,以便它与未来的3.0兼容

(最好是简短的甜蜜的表情

,我可以嵌入列表理解中)?



itertools.chain或sum(x,[])


According to the following page on Wikipedia:
http://en.wikipedia.org/wiki/Python_...re_development
reduce is going to be removed in python 3.0. It talks of an
accumulation loop; I have no idea what that''s supposed to mean. So,

===============================

>>x =

[[1,2,3],
[4,5,6],
[7,8,9]]

>>reduce(lambda a,b:a+b, x, [])

[1, 2, 3, 4, 5, 6, 7, 8, 9]
===============================

What''s an accumulation loop, and how would I convert this code so it''s
compatible with the future 3.0 (preferably in a short sweet expression
that I can embed in a list comprehension)?

解决方案

Dustan wrote:

What''s an accumulation loop, and how would I convert this code so it''s
compatible with the future 3.0

the release of Python 3.0 is far away, and nobody knows how it''s going
to look. trying to be future-compatible at this time is a major waste
of time and (not quite as wasteful as reopening yet another old "let''s
make some pointless change to the language" thread, but almost).

surely you must have something better to do with your time ?

</F>


Fredrik Lundh wrote:

Dustan wrote:

What''s an accumulation loop, and how would I convert this code so it''s
compatible with the future 3.0


the release of Python 3.0 is far away, and nobody knows how it''s going
to look. trying to be future-compatible at this time is a major waste
of time and (not quite as wasteful as reopening yet another old "let''s
make some pointless change to the language" thread, but almost).

surely you must have something better to do with your time ?

</F>

It''s always nice to know there are such good-natured people ready to
help on this group. Anyway, I figured out a way to get the builtin
function ''sum'' to work as I need:
sum([[1,2,3],[4,5,6],[7,8,9]], [])

On an unrelated note, can anyone explain this unpredictable behavior on
IDLE? I swear I never hit ctrl-c...
==============================

>>help(sum)

Help on built-in function sum in module __builtin__:

sum(...)
sum(sequence, start=0) -value

Returns the sum of a sequence of numbers (NOT strings) plus the
value
of parameter ''start''. When the sequence is empty, returns start.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
help(sum)
File "C:\Python25\lib\site.py", line 346, in __call__
return pydoc.help(*args, **kwds)
File "C:\Python25\lib\pydoc.py", line 1642, in __call__
self.help(request)
File "C:\Python25\lib\pydoc.py", line 1687, in help
self.output.write(''\n'')
File "C:\Python25\lib\idlelib\PyShell.py", line 1246, in write
self.shell.write(s, self.tags)
File "C:\Python25\lib\idlelib\PyShell.py", line 1235, in write
raise KeyboardInterrupt
KeyboardInterrupt
==============================



Dustan wrote:

According to the following page on Wikipedia:
http://en.wikipedia.org/wiki/Python_...re_development
reduce is going to be removed in python 3.0. It talks of an
accumulation loop; I have no idea what that''s supposed to mean. So,

===============================

>x =

[[1,2,3],
[4,5,6],
[7,8,9]]

>reduce(lambda a,b:a+b, x, [])

[1, 2, 3, 4, 5, 6, 7, 8, 9]
===============================

What''s an accumulation loop, and how would I convert this code so it''s
compatible with the future 3.0 (preferably in a short sweet expression
that I can embed in a list comprehension)?

itertools.chain or sum(x,[])


这篇关于减少被删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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