@1chimaruGin let’s have another example:
from torch.utils.data import Dataset

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)


dataset = NumbersDataset()

len(dataset), len(list(dataset))
>>> 500, 1000

Ho does list() know that it should iterate over .samples1 and not .samples2 which has only 10 items?