I have an XML tree like:
<abc>
<cd>text1</cd>
<cd>text2</cd>
<ef>text3</ef>
<ef>text4</ef>
</abc>
Now I want to save it as a list with tuples like: [(text1,text3),(text2,text4)] .
How do i do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
yields
Explanation:
You already know how to parse the XML into a list like this:
To group items by 2, use the grouper recipe,
zip(*[iter]*2):Now you can use zip again to group the first items from each tuple, then the second items, etc: