def _write_instance(entity, value, sep = '&'):

    """Helper function to write the search string.

    Helps to write the search string, can handle lists and values.
    The different entities have to be known and can be found out with the documentation.

    Parameters
    ----------
    entity : string
        The name of the search Parameters.

    value : string or list
        The values corresponding to the entity.

    sep :  string
        The separator between the search parameters and values, most times OS takes '&'.

    Returns
    -------
    string
        String with the 'entities=values&....', such that Openspecimen can dissolve it.
    """
    
    instance= ''
    if isinstance(value,list):
        for val in value:
            instance += str(entity) + '=' + str(val).replace(' ', '+') + str(sep)
    else:
        instance += str(entity) + '=' + str(value).replace(' ', '+') + str(sep)

        return instance