Advantage of itertools over range

I noticed that in the Data Loader class, get_idxs is written as follows

def get_idxs(self):
        idxs = Inf.count if self.indexed else Inf.nones
        if self.n is not None: idxs = list(itertools.islice(idxs, self.n))
        if self.shuffle: idxs = self.shuffle_fn(idxs)
        return idxs

What is the advantage of creating an infinite count of indexes and slicing them instead of using something like range?

self.n might be None.


If self.n is None it means something is broken, correct? In this case, we return an infinite list of nones. But when I print that, it shows me an empty list. How does that work?

Also if you could point me to some good resources to learn about the functional programming stuff that you mention, that’ll be great.