Understanding DataLoader class

Hi, Im triying to understand what does “zip” in this code does, and why does it work this way , because when I try to “zip” any dataset[n] example , it returns an error which says “zip argument #2 must support iteration”.

def collate(b):
xs,ys = zip(*b)
return torch.stack(xs),torch.stack(ys)

class DataLoader():
    def __init__(self, ds, sampler, collate_fn=collate):
        self.ds,self.sampler,self.collate_fn = ds,sampler,collate_fn   
def __iter__(self):
    for s in self.sampler: yield self.collate_fn([self.ds[i] for i in s])

This code is from fast.ai v3 part 2 “03_minibatch_training.ipynb”.

Hi @sergiogaitan zip(*b) unpacked individual (x,y) tuples back into a tuple where all the xs in one and ys in another one.