J. Clifford Dyer wrote:
> 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.
>
>   
Also, as noted elsewhere in the string, your C is actually a list of
Cs.  So replace my else statement with

return [(child[0], reduceXML(child[2])) for child in node]

I think that'll do what you need.  However, I'm not sure why you need
to.  You're not getting any new information out of your data structure. 
Why not just ignore the attributes and the spare tuplet (or whatever you
call tuple-items) when you do the real processing next time through?

Cheers,
Cliff

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

Reply via email to