<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def set_instances(name, instances, test=False, region=None, key=None, keyid=None,
                         profile=None):
    '''
    Set the instances assigned to an ELB to exactly the list given

    CLI example:

    .. code-block:: bash

        salt myminion boto_elb.set_instances myelb region=us-east-1 instances="[instance_id,instance_id]"
    '''
    ret = True
    current = set([i['instance_id'] for i in get_instance_health(name, region, key, keyid, profile)])
    desired = set(instances)
    add = desired - current
    remove = current - desired
    if test:
        return bool(add or remove)
    if remove:
        if deregister_instances(name, list(remove), region, key, keyid, profile) is False:
            ret = False
    if add:
        if register_instances(name, list(add), region, key, keyid, profile) is False:
            ret = False
    return ret