Skip to content

Instantly share code, notes, and snippets.

@kindly
Last active September 21, 2018 17:16
Show Gist options
  • Select an option

  • Save kindly/2232655f6d950413f3788be44c864151 to your computer and use it in GitHub Desktop.

Select an option

Save kindly/2232655f6d950413f3788be44c864151 to your computer and use it in GitHub Desktop.
import sys
from lxml import etree
root = etree.parse(sys.argv[1])
actual_results = {}
for num, result in enumerate(list(root.iter("result"))):
title = num
title_element = result.find("title")
if title_element is not None:
narrative_element = title_element.find("narrative")
if narrative_element is not None:
title = narrative_element.text.strip()
if title in actual_results:
result_element = actual_results[title]
for indicator_element in result.iter("indicator"):
result_element.append(indicator_element)
result.getparent().remove(result)
else:
actual_results[title] = result
print(etree.tostring(root, pretty_print=True).decode())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment