peng/functions.py
def _remove_consecutive_delims(expr, ldelim="(", rdelim=")"):
    """Remove consecutive delimiters."""
    tpars = _pair_delims(expr, ldelim=ldelim, rdelim=rdelim)
    # Flag superfluous delimiters
    ddelim = []
    for ctuple, ntuple in zip(tpars, tpars[1:]):
        if ctuple == (ntuple[0] - 1, ntuple[1] + 1):
            ddelim.extend(ntuple)
    ddelim.sort()
    # Actually remove delimiters from expression
    for num, item in enumerate(ddelim):
        expr = expr[: item - num] + expr[item - num + 1 :]
    # Get functions
    return expr
def _remove_consecutive_delims(expr, ldelim="(", rdelim=")"):
    """Remove consecutive delimiters."""
    tpars = _pair_delims(expr, ldelim=ldelim, rdelim=rdelim)
    # Flag superfluous delimiters
    ddelim = []
    for ctuple, ntuple in zip(tpars, tpars[1:]):
        if ctuple == (ntuple[0] - 1, ntuple[1] + 1):
            ddelim.extend(ntuple)
    ddelim.sort()
    # Actually remove delimiters from expression
    for num, item in enumerate(ddelim):
        expr = expr[: item - num] + expr[item - num + 1 :]
    # Get functions
    return expr
Remove consecutive delimiters.