愿望清单项目:itertools.flatten [英] Wishlist item: itertools.flatten

查看:61
本文介绍了愿望清单项目:itertools.flatten的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于快速和肮脏的东西,平整一个序列通常很方便

(默认情况下perl会这样做,惊喜):


[1,2,[3," hello,[[4]]]] - >


[1,2,3,''你好'' ,4)


其中一个实现是

http://aspn.activestate.com/ASPN/Mai...-tutor/2302348


但这样的东西在itertools中也会很方便。


看起来很简单,但是在尝试生成

时我设法搞砸了好几次我自己的实现(无限递归)。


-

Ville Vainio http://tinyurl.com/2prnb

For quick-and-dirty stuff, it''s often convenient to flatten a sequence
(which perl does, surprise surprise, by default):

[1,2,[3,"hello",[[4]]]] ->

[1, 2, 3, ''hello'', 4]

One such implementation is at

http://aspn.activestate.com/ASPN/Mai...-tutor/2302348

but something like this would be handy in itertools as well.

It seems trivial, but I managed to screw up several times when trying
to produce my own implementation (infinite recursion).

--
Ville Vainio http://tinyurl.com/2prnb

推荐答案

2005年3月11日13:32: 45 + 0200,传言说Ville Vainio

< vi *** @ spammers.c OM>可能写得:
On 11 Mar 2005 13:32:45 +0200, rumours say that Ville Vainio
<vi***@spammers.com> might have written:
对于快速和肮脏的东西,平整一个序列通常很方便
(Perl会这样做,出乎意料的是,默认情况下):

[1,2,[3," hello,[[4]]]] - >

[1,2,3,''你好' ',4]

其中一个实现是

http://aspn.activestate.com/ASPN/Mai...-tutor/2302348

但是这样的话会在itertools中也很方便。

这看起来微不足道,但是当我尝试生成我自己的实现(无限递归)时,我设法搞砸了几次。
For quick-and-dirty stuff, it''s often convenient to flatten a sequence
(which perl does, surprise surprise, by default):

[1,2,[3,"hello",[[4]]]] ->

[1, 2, 3, ''hello'', 4]

One such implementation is at

http://aspn.activestate.com/ASPN/Mai...-tutor/2302348

but something like this would be handy in itertools as well.

It seems trivial, but I managed to screw up several times when trying
to produce my own implementation (infinite recursion).




参见Python Library Reference,5.16.3 Recipes。现在所有和任何(也作为食谱在那里呈现的b $ b)被认为是包括在内,也许flatten得到

a机会。


这只是一个个人意见,但我在讨论这些有用的*积木*时讨厌对库(迭代工具

模块)的扩展*。

什么碰巧包含电池?

-

TZOTZIOY,我说英格兰最好。

发送和容忍时要严格在接收时。 (来自RFC1958)

我真的应该在与人交谈时牢记这一点,实际上......



See Python Library Reference, "5.16.3 Recipes". Now that all and any (also
presented as recipes there) are considered to be included, perhaps flatten gets
a chance too.

This is just a personal opinion, but I detest restraints on library (itertools
module in this case) expansion when talking about such useful *building blocks*.
What happened to "batteries included"?
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...


>>>> ;> "&的Christos QUOT; == TZOTZIOY< Christos>写道:
>>>>> "Christos" == TZOTZIOY <Christos> writes:
对于快速和肮脏的东西,平整一个序列通常很方便
(Perl会这样做,惊喜惊喜,默认情况下):

[1,2,[3," hello,[[4]]]] - >

[1,2, 3,''你好'',4]
For quick-and-dirty stuff, it''s often convenient to flatten a sequence
(which perl does, surprise surprise, by default):

[1,2,[3,"hello",[[4]]]] ->

[1, 2, 3, ''hello'', 4]




Christos>请参阅Python库参考,5.16.3配方。现在

Christos>所有和任何(也是


食谱是:


def flatten(listOfLists):

返回列表(链(* listOfLists))


那个是微不足道的,因为它只会使一个级别变平。

我正在谈论的扁平化涉及扁平化任意深度

得到单个序列的atoms。itertools实现可能

也可以通过使用堆栈来避免递归。


Christos>这只是一个个人意见,但我讨厌限制

Christos>在库(本例中为itertools模块)扩展

Christos>时谈论这些有用的*积木*。


是的 - 特别是在扁平化的情况下。如果它被认为是有用的

是默认行为在perl(这是公认的braindamaged),

它肯定值得保证作为单个函数包含在

stdlib中。


-

Ville Vainio http://tinyurl.com/2prnb


2005年3月12日00:44:39 +0200,谣言说Ville Vainio

< vi *** @ spammers.com>可能写得:
On 12 Mar 2005 00:44:39 +0200, rumours say that Ville Vainio
<vi***@spammers.com> might have written:
Christos>这只是个人意见,但我讨厌克制。
Christos>在库(本例中为itertools模块)扩展
Christos>在谈论这些有用的*积木时*。

是的 - 尤其是在扁平化的情况下。如果它被认为是有用的,可以成为perl中的默认行为(这无疑是braindamaged),
它肯定有必要作为单个函数包含在
stdlib中。
Christos> This is just a personal opinion, but I detest restraints
Christos> on library (itertools module in this case) expansion
Christos> when talking about such useful *building blocks*.

Yeah - esp. in the case of flattening. If it was deemed useful enough
to be the default behavior in perl (which is admittedly braindamaged),
it should surely warrant being included as a single function in the
stdlib.




或者一个窗口函数,我需要足够的时间在*单独的*场合

将它添加到我的个人stdlib中。模块(暗示它可能是

itertools的一部分):


window(''hello'',2)=> ''他',''el'',''l'',''lo''

-

TZOTZIOY,我说英格兰最好。

发送时要严格,接收时要宽容。 (来自RFC1958)

我真的应该在与人交谈时牢记这一点,实际上......



Or a window function, which I have needed enough times in *separate* occasions
to add it in one of my personal "stdlib" modules (hinting it could be part of
itertools):

window(''hello'', 2) => ''he'', ''el'', ''ll'', ''lo''
--
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...


这篇关于愿望清单项目:itertools.flatten的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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