On Fri, Oct 26, 2007 at 06:59:51AM -0700, [EMAIL PROTECTED] wrote regarding Re: 
tuples within tuples:
> 
> > Resolve *what*?  The problem isn't clear yet; at least to me.  Above you
> > say what you get.  What exactly do you want?  Examples please.
> >
> 
> 
> Sorry for my poor english, but I meant: how can I obtain a list of A
> and C starting from something like this?
> 
> (A,B,C,D)
> that could be
> ('tagA', None, [('tagB', None, ['bobloblaw], None)], None)
> but also
> ('tagA', None, description, None)
> when I don't know if C is a tuple or not?
> 
> I guess that, at least,  within the cicle I may test if C is a tuple
> or not.. And then apply the same cicle for C... and so on
> 
> Am i right?
> 
> 
> ciao
> korovev

So, to clarify the piece that you still haven't explicitly said, you want to 
keep the tag name and children of every element in your XML document.  (which 
is different from keeping (A, C) from tuple (A, B, C, D), because you want to 
modify C as well, and it's decendants.)

As a first solution, how about: 

def reduceXML(node):
    if type(node) == str:
                return node
        else: 
                return (node[0], reduceXML(node[2])

N.B. Beware of stack limitations.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to