from functools import reduce
from operator import add


def _set_number_of_tips(tree):
    """Sets .ntips

    Notes
    -----
    Operates in place
    """
    for node in tree.postorder():
        if node.is_tip():
            node.ntips = 1
        else:
            node.ntips = reduce(add, [child.ntips for child in node.children])
    return tree