Hello @ptrblck thanks a lot for your help. This is how I did it:
train_data = datasets.MNIST(root='~/.pytorch/MNIST_data/', train=True,
                                   download=True, transform=transform)
train_set = [] 

for i in range(0,len(train_data)):
    if train_data[i][1] < 7:
        train_set.append(train_data[i])