def index_name_if_in_list(name, name_list, suffix='', prefix=''):
    """
    Find a unique name by adding an index to the name so it is unique within the given list.

    Parameters:
        name (str): Name
        name_list (iterable): List of names that the new name must differ from.
        suffix (str): The suffix to append after the index.
        prefix (str): The prefix to append in front of the index.

    Returns:
        str: A unique name within the given list.
    """
    new_name = '{}'.format(name)
    index = 1

    while new_name in name_list:
        new_name = '{}_{}{}{}'.format(name, prefix, index, suffix)
        index += 1

    return new_name
Find a unique name by adding an index to the name so it is unique within the given list.

    Parameters:
        name (str): Name
        name_list (iterable): List of names that the new name must differ from.
        suffix (str): The suffix to append after the index.
        prefix (str): The prefix to append in front of the index.

    Returns:
        str: A unique name within the given list.