Can someone explain to me step by step to understand how to arrive at the result of this loop?
>>> [ (a, b) for a in range(3) for b in range(a) ]
[(1, 0), (2, 0), (2, 1)]
Can someone explain to me step by step to understand how to arrive at the result of this loop?
>>> [ (a, b) for a in range(3) for b in range(a) ]
[(1, 0), (2, 0), (2, 1)]
It's equivalent to this:
rtrn = []
for a in range(3):
for b in range(a):
rtrn.append((a, b))
Note how the first iteration of the outer loop does not produce any output because the inner loop is then range(0)
which does zero iterations.