<commit_before>#!/usr/bin/env python
from __future__ import print_function

import sys
import argparse

from lxml import etree

NS = {'x': 'http://www.w3.org/1999/xhtml',
      'mml':'http://www.w3.org/1998/Math/MathML'}

body_xpath = etree.XPath('//x:body', namespaces=NS)

math_xpath = etree.XPath("//mml:math", namespaces=NS)


def main(html_in, html_out=sys.stdout):
    """Extract math nodes from book html file"""

    html = etree.parse(html_in)

    body = body_xpath(html)[0]

    math = math_xpath(body)

    for c in body.iterchildren():
        body.remove(c)

    for m in math:
        body.append(m)

    print(etree.tostring(html), file=html_out)


if __name__ == '__main__':
<commit_msg>Use clear() instead of manually deleting all elements in the body<commit_after>#!/usr/bin/env python
from __future__ import print_function

import sys
import argparse

from lxml import etree

NS = {'x': 'http://www.w3.org/1999/xhtml',
      'mml':'http://www.w3.org/1998/Math/MathML'}

body_xpath = etree.XPath('//x:body', namespaces=NS)

math_xpath = etree.XPath("//mml:math", namespaces=NS)


def main(html_in, html_out=sys.stdout):
    """Extract math nodes from book html file"""

    html = etree.parse(html_in)

    body = body_xpath(html)[0]

    math = math_xpath(body)

    body.clear()

    for m in math:
        body.append(m)

    print(etree.tostring(html), file=html_out)


if __name__ == '__main__':

{'fraction_non_alphanumeric': 0.14788732394366197, 'fraction_numerical': 0.015492957746478873, 'mean_word_length': 3.6136363636363638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6517709', 'n_tokens_mistral': 557, 'n_tokens_neox': 521, 'n_words': 116}