Apr 22, 2024
In fact, there's a more general way to do this, which doesn't require the iterators to have been expanded, and allows inner iterators to depend on the values of the outer ones:
x = []
for i in range(10):
for j in range(i + 1, 10):
x.append((i, j))
becomes:
x = [(i, j) for i in range(10) for j in range(i + 1, 10)]