def strip_token(str_, token, is_token_list=False, compat=True):
    "Returns a copy of strings with leading and trailing tokens removed.\n\n    Note that besides :attr:`token`, all leading and trailing whitespace\n    characters are also removed.\n\n    If :attr:`is_token_list` is False, then the function assumes tokens in\n    :attr:`str_` are separated with whitespace character.\n\n    Args:\n        str_: A `str`, or an `n`-D numpy array or (possibly nested)\n            list of `str`.\n        token (str): The token to strip, e.g., the '<PAD>' token defined in\n            :class:`~texar.tf.data.SpecialTokens`.PAD\n        is_token_list (bool): Whether each sentence in :attr:`str_` is a list\n            of tokens. If False, each sentence in :attr:`str_` is assumed to\n            contain tokens separated with space character.\n        compat (bool): Whether to convert tokens into `unicode` (Python 2)\n            or `str` (Python 3).\n\n    Returns:\n        The stripped strings of the same structure/shape as :attr:`str_`.\n\n    Example:\n\n        .. code-block:: python\n\n            str_ = '<PAD> a sentence <PAD> <PAD>  '\n            str_stripped = strip_token(str_, '<PAD>')\n            # str_stripped == 'a sentence'\n\n            str_ = ['<PAD>', 'a', 'sentence', '<PAD>', '<PAD>', '', '']\n            str_stripped = strip_token(str_, '<PAD>', is_token_list=True)\n            # str_stripped == 'a sentence'\n    "

    def _recur_strip(s):
        if is_str(s):
            if (token == ''):
                return ' '.join(s.strip().split())
            else:
                return ' '.join(s.strip().split()).replace((' ' + token), '').replace((token + ' '), '')
        else:
            s_ = [_recur_strip(si) for si in s]
            return _maybe_list_to_array(s_, s)
    s = str_
    if compat:
        s = compat_as_text(s)
    if is_token_list:
        s = str_join(s, compat=False)
    strp_str = _recur_strip(s)
    if is_token_list:
        strp_str = _recur_split(strp_str, str_)
    return strp_str
Returns a copy of strings with leading and trailing tokens removed.

Note that besides :attr:`token`, all leading and trailing whitespace
characters are also removed.

If :attr:`is_token_list` is False, then the function assumes tokens in
:attr:`str_` are separated with whitespace character.

Args:
    str_: A `str`, or an `n`-D numpy array or (possibly nested)
        list of `str`.
    token (str): The token to strip, e.g., the '<PAD>' token defined in
        :class:`~texar.tf.data.SpecialTokens`.PAD
    is_token_list (bool): Whether each sentence in :attr:`str_` is a list
        of tokens. If False, each sentence in :attr:`str_` is assumed to
        contain tokens separated with space character.
    compat (bool): Whether to convert tokens into `unicode` (Python 2)
        or `str` (Python 3).

Returns:
    The stripped strings of the same structure/shape as :attr:`str_`.

Example:

    .. code-block:: python

        str_ = '<PAD> a sentence <PAD> <PAD>  '
        str_stripped = strip_token(str_, '<PAD>')
        # str_stripped == 'a sentence'

        str_ = ['<PAD>', 'a', 'sentence', '<PAD>', '<PAD>', '', '']
        str_stripped = strip_token(str_, '<PAD>', is_token_list=True)
        # str_stripped == 'a sentence'
def strip_token(str_, token, is_token_list=False, compat=True):
    "Returns a copy of strings with leading and trailing tokens removed.\n\n    Note that besides :attr:`token`, all leading and trailing whitespace\n    characters are also removed.\n\n    If :attr:`is_token_list` is False, then the function assumes tokens in\n    :attr:`str_` are separated with whitespace character.\n\n    Args:\n        str_: A `str`, or an `n`-D numpy array or (possibly nested)\n            list of `str`.\n        token (str): The token to strip, e.g., the '<PAD>' token defined in\n            :class:`~texar.tf.data.SpecialTokens`.PAD\n        is_token_list (bool): Whether each sentence in :attr:`str_` is a list\n            of tokens. If False, each sentence in :attr:`str_` is assumed to\n            contain tokens separated with space character.\n        compat (bool): Whether to convert tokens into `unicode` (Python 2)\n            or `str` (Python 3).\n\n    Returns:\n        The stripped strings of the same structure/shape as :attr:`str_`.\n\n    Example:\n\n        .. code-block:: python\n\n            str_ = '<PAD> a sentence <PAD> <PAD>  '\n            str_stripped = strip_token(str_, '<PAD>')\n            # str_stripped == 'a sentence'\n\n            str_ = ['<PAD>', 'a', 'sentence', '<PAD>', '<PAD>', , ]\n            str_stripped = strip_token(str_, '<PAD>', is_token_list=True)\n            # str_stripped == 'a sentence'\n    "

    def _recur_strip(s):
        if is_str(s):
            if (token == ):
                return ' '.join(s.strip().split())
            else:
                return ' '.join(s.strip().split()).replace((' ' + token), ).replace((token + ' '), )
        else:
            s_ = [_recur_strip(si) for si in s]
            return _maybe_list_to_array(s_, s)
    s = str_
    if compat:
        s = compat_as_text(s)
    if is_token_list:
        s = str_join(s, compat=False)
    strp_str = _recur_strip(s)
    if is_token_list:
        strp_str = _recur_split(strp_str, str_)
    return strp_str