/dev/random

Python itertools.product and nested loops

n = 7
m = 3

# m = 3, so 3 nested loops
foo = []
for i in range(n):
    for j in range(n):
        for k in range(n):
            foo.append((i, j, k))


import itertools
bar = list(itertools.product(*[range(n) for _ in range(m)]))

assert foo == bar