I want to delete a sample if does not hold a certain condition. I cannot check for this condition beforehand.  I wrote the sample code on how I wanted it to work.
Will this work?
If not how should i do it.
class Mydataset(Dataset):

    def __init__(self, data_list):

        self.data = data_list

    def __len__(self):
        return len(self.data)

    def __getitem__(self, idx):
         if some_condition:
               sample = self.data[idx]
        else:
               del self.data[idx]
               self.__getitem__(idx)

        return sample