<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sampler_to_iterator(dataset, sampler):
 """ Given a batch sampler or sampler returns examples instead of indices Args: dataset (torch.utils.data.Dataset):
 Dataset to sample from. sampler (torch.utils.data.sampler.Sampler):
 Sampler over the dataset. Returns: generator over dataset examples """

    for sample in sampler:
        if isinstance(sample, (list, tuple)):
            # yield a batch
            yield [dataset[i] for i in sample]
        else:
            # yield a single example
            yield dataset[sample]