import re


def replace_disallowed(sequence, symbols, replacement):
    """Replace tokens or fields in a sequence based on symbols they contain.

    Parameters
    ----------
    sequence : collection of str or collections
        Sequence of tokens to be replaced.
    symbols : str
        Symbols that are allowed. Tokens containing other symbols are replaced.
    replacement : object
        Object (typically string) that illegal tokens are replaced with

    Notes
    -----
    If token is not string, but a collection of strings, each element
    in the collection will be replaced if it contains disallowed symbols
    """
    disallowed_characters = re.compile(f"[^{symbols}]")
    replaced = list()

    for token in sequence:
        if isinstance(token, str):
            if disallowed_characters.search(token):
                token = replacement

        else:
            token = [field if not disallowed_characters.search(field)
                     else replacement
                     for field in token]

        replaced.append(token)

    return replaced