Although this doesn’t answer my question, you are completely right… My code overwrites the last 10 samples of “dataset” with the second batch of dataset2, as opposed to what I was trying to do. Thanks for that.
My problem is that when I use the classes “DatasetFolder1” and “DatasetFolder2” that are derived from “torchvision.datasets.DatasetFolder”, the objects “dataset1” and “dataset2” contain several variables (such as “classes”, “extensions”, “samples”) that are omitted in the new object “dataset” when I use

dataset = [dataset1[i] for i in range(20) ]

As far as I can see, the problem is that the object “dataset” is no longer of type “DatasetFolder” (it is just a list). Is there anyway of just creating a new “DatasetFolder” instance with some samples coming from dataset1 and some from dataset2?
Hope I made myself clear.
Thanks!