def _suitability(node, word, mx):
    children = node.getchildren()
sparsity = 1
result = float(node.text_content().lower().count(word))
for child in children:
    res, spars = _suitability(child, word, mx)
result += res
sparsity += spars
result /= sparsity
current_max, max_node = mx
if current_max < result:
    mx[0] = result
mx[1] = node
return result, sparsity
print(suitability(node, 'foo'))
Find an HTML element which contains the largest number of mentions of given word