def quick_penalty(tensor_or_tensors, penalty):
    """
    Computes the total cost for applying a specified penalty
    to a tensor or group of tensors.
    Parameters
    ----------
    tensor_or_tensors : Theano tensor or list of tensors
    penalty : 'l1' or 'l2'
    Returns
    -------
    Theano scalar
        a scalar expression for the total penalty cost
    """
    return sum(eval(penalty)(x) for x in tensor_or_tensors)