for me something like
def update_datasamplers(dset, slides, batch_size, batch_samplers: dict):
    indices = np.arange(len(dset))
    train_idc = []
    valid_idc = []
    test_idc  = []

    for slide_id in np.concatenate(slides):
        if slide_id in slides[0]:
            train_idc.extend(indices[slide_id == dset.domains])
        if slide_id in slides[1]:
            valid_idc.extend(indices[slide_id == dset.domains])
        if slide_id in slides[2]:
            test_idc.extend(indices[slide_id == dset.domains])

    batch_samplers["train"].sampler.indices = train_idc
    batch_samplers["valid"].sampler.indices = valid_idc
    batch_samplers["test"].sampler.indices = test_idc


worked since python usually uses something similar to call by reference. Depending on your code (where you want to call update_datasamplers) you could also directly pass the loaders and access the sampler indices via loader.batch_sampler.sampler.indices