Is it possible to write a function that adds more for loops to a nested loop. So lets say I have a function for_loops(3).
def for_loops(n):
a = []
for add_v in range(n):
a.append("AB")
for i in range(len(a[0])):
for j in range(len(a[1])):
for k in range(len(a[2])):
print(a[0][i]+" "+a[1][j]+" "+a[2][k])
for_loops(3)
then for_loops(4)
def for_loops(n):
a = []
for add_v in range(n):
a.append("AB")
for i in range(len(a[0])):
for j in range(len(a[1])):
for k in range(len(a[2])):
for l in range(len(a[3])):
print(a[0][i]+" "+a[1][j]+" "+a[2][k]+" "+a[3][l])
for_loops(4)
itertools.productdocs.python.org/2.7/library/itertools.html#itertools.product But I agree with Morgan Thrapp, this approach seems like it probably isn't ideal.