On Sun, 7 Mar 2010 17:20:07 +0100
Hugo Arts wrote:
> On Sun, Mar 7, 2010 at 1:58 PM, spir wrote:
> > Hello,
> >
> > Is it possible at all to have a recursive generator? I think at a iterator
> > for a recursive data structure (here, a trie). The following code does not
> > work: it only yields
On 7 March 2010 12:58, spir wrote:
> Hello,
>
> Is it possible at all to have a recursive generator? I think at a iterator
> for a recursive data structure (here, a trie). The following code does not
> work: it only yields a single value. Like if child.__iter__() were never
> called.
>
> def
Here's a (more or less) useful example. It generates the "nth triangular
series" (my term), n=2 is the triangular numbers, n=3 the tetrahedral numbers
(n has a correspondence to dimension). Each series is the sum of the elements
of the previous one. They are also the columns of Pascal's Tria
sorry, forgot to forward this to the list.
On Sun, Mar 7, 2010 at 1:58 PM, spir wrote:
> Hello,
>
> Is it possible at all to have a recursive generator? I think at a iterator
> for a recursive data structure (here, a trie). The following code does not
> work: it only yields a single value. Like
On Mon, 8 Mar 2010 01:49:21 am Stefan Behnel wrote:
> Steven D'Aprano, 07.03.2010 14:27:
> > __iter__ should be an ordinary function, not a generator. Something
> > like this should work:
[...]
> That's just an unnecessarily redundant variation on the above. It's
> perfectly ok if __iter__() is a g
Steven D'Aprano, 07.03.2010 14:27:
On Sun, 7 Mar 2010 11:58:05 pm spir wrote:
def __iter__(self):
''' Iteration on (key,value) pairs. '''
print '*',
if self.holdsEntry:
yield (self.key,self.value)
for child in self.children:
prin
On Sun, 7 Mar 2010 11:58:05 pm spir wrote:
> Hello,
>
> Is it possible at all to have a recursive generator?
Yes.
>>> def recursive_generator(n):
... if n == 0:
... return
... yield n
... for i in recursive_generator(n-1):
... yield i
...
>>> it = recursive_generato
Hello,
Is it possible at all to have a recursive generator? I think at a iterator for
a recursive data structure (here, a trie). The following code does not work: it
only yields a single value. Like if child.__iter__() were never called.
def __iter__(self):
''' Iteration on (key,val