Versus:

class NumbersDataset(Dataset):
    def __init__(self):
        self.samples1 = list(range(1, 1001))
        self.samples2 = list(range(1, 11))

    def __len__(self):
        return len(self.samples1)-500

    def __getitem__(self, idx):
        return self.samples1[idx]
      
    def __iter__(self):
      return iter(self.samples1)



In python, __getitem__ in class make it iterable.
stackoverflow Q&A 1 about getitem.