for a in map:
for b in map[a]:
for c in map[b]:
for d in map[c]:
for e in map[d]:
print a+b+c+d+e
The above code is used to create all paths of certain length in a graph. map[a] represents the points you can reach from point a.
How can I change it to simulate having an arbitrary number of loops?
This is like a cartesian product (itertools.product) where at each iteration your choice for the next element is limited to those in map[current_point].