Split train set into datasets for each class

I have several datasets define in this fashion:-

trainset = torchvision.datasets.CIFAR10(root='path_to_CIFAR10', train=True, download=True)
trainset = torchvision.datasets.CIFAR100(root='path_to_CIFAR100', train=True, download=True)
trainset = torchvision.datasets.SVHN(root='path_to_SVHN', split='train', download=True)
trainset = torchvision.datasets.GTSRB(root='path_to_GTSRB', split='train', download=True)

I apply data transforms separately before creating the dataloaders.

What would be the most efficient way to split each trainset into sets where each set has only data of one particular class ?

I’d prefer to create the sets and store them in a list so that I can iterate over each classes’ set.