def depth(expr):
    """
    depth(expr) finds the depth of the mathematical expr formatted as a list.
    depth is defined as the deepest level of nested operations within the expression.
    """
    if not isinstance(expr, list):
        raise TypeError("depth() : expr must be of type list")
    else:
        exprlength = len(expr) # number of nodes at current recursion level
        depths = [0]*exprlength # depth beneath each node at the current level

        # for every node at the current level
        for ii in range(exprlength):

            # if the node has branches
            if isinstance(expr[ii], list):

                # increment depth and recurse down the branch
                depths[ii] = 1 + depth(expr[ii])

        # pass up the deepest depth beneath the current level
        return max(depths)