Recursive function returning a list

Boris Borcic bborcic at gmail.com
Wed Jul 19 08:36:36 EDT 2006


Bruno Desthuilliers wrote:
> Boris Borcic a écrit :
>> Hello Bruno,
>>
>> Bruno Desthuilliers wrote:
>>
>>> Boris Borcic wrote:
>>>
>>>>> Do you have any ideas?
>>>>
>>>>
>>>> you could use a recursive generator, like
>>>>
>>>> def genAllChildren(self) :
>>>>     for child in self.children :
>>>>         yield child
>>>>         for childchild in child.genAllChildren() :
>>>>             yield childchild
>>>
>>>
>>>
>>> Or how to *not* address the real problem...
>>>
>>> Boris, using a generator may be a pretty good idea, but *not* as a way
>>> to solve a problem that happens to be a FAQ !-)
>>>
>>
>> Sorry, but I don't understand your reasoning.
> 
> It's quite simple. The OP's problem is well-known (it's a FAQ),

This is really an oversimplification. What's the case is that his showstopper 
was covered by the FAQ list. The OP's "problem" is actually a stack of 
problems/subproblems and was presented as such.

> and easy 
> to solve.

I did consider a couple distinct ways to solve "it" while passing lists around - 
did you notice that the OP's code made no clear choice as to whether it wanted 
to pass them by reference or as return values ? That's how a generator struck me 
as most pythonic if you want ("In the face of ambiguity, refuse the temptation 
to guess").

> The righ answer to it is obviously to give a link to the FAQ 
> (or take time to re-explain it for the zillionth time), not to propose a 
> workaround.

Given your usage of code simplicity in another thread as (roughly) a measure of 
pythonic virtue, I feel it warranted to ask why should one recognize simpler 
code as "the workaround" (assuming it fits the bill) ?

Because it doesn't cross the FAQ, seems to be your answer...

> 
>> How can you exclude that the OP /may/ find that a generator neatly 
>> solves his problem ?
> 
> I don't exclude it, and explicitly mentioned in whole letters that, I 
> quote, it "may be a pretty good idea". And actually, the OP's problem is 
> really with default values evaluation scheme - something that every 
> Python programmer should know, because there are cases where you cannot 
> solve it with a generator-based solution !-)
...
 >> - and the quirks of default values being FAQ stuff don't change that.
 >> Sure if nobody had covered that aspect, but a couple other posters did...
 >
 > Yes, but you forgot to mention that - and I would not have post any
 > comment on your solution if you had explicitly mentioned the FAQ or
 > these other answers.

At this point I recognize that our difference may very well have deep roots 
relating to cognitive style, educational policy, etc. Generally speaking I 
welcome debate on such premisses as an occasion to learn more (not so much from 
my contradictor than from the debate itself), but a precondition is that the 
partner/contradictor understands my motive (what I can't count on since the idea 
of learning from the debate itself is pretty typical such cognitive style 
divides). Besides, I don't quite have the time right now.

The short form is : "I strongly disagree with you".

Best, BB
--
"On naît tous les mètres du même monde"



More information about the Python-list mailing list