Custom DataLoader for passing paired data (no augmentation for creation)

I want to write a custom dataset, where I want to create pair from two different datasets based on its label.
For this I need to use nested loop in the data loader. But whenever I am trying to write loop inside the get_item(self,index) it is not working.

Or I need to write this part somewhere else.
For a given index, I want to match its label and pair it with data points of other dataset and return all the combinations.