def __len__(self):
        """Returns the number of elements (nodes) in the tree."""
        ret = 0
        for elem in self:
            ret += 1
        return ret
Returns the number of elements (nodes) in the tree.
recipes/Python/136529_Trees_and_more_trees/recipe-136529.py