I am trying to print out all the possible combinations of two lists, so for example if list1 has values {1,2,3} and list two has values {A,B,C} I should get the following:
A=1 B=1 C=1
A=1 B=1 C=2
A=1 B=1 C=3
A=1 B=2 C=1
A=1 B=2 C=2
A=1 B=2 C=3
A=1 B=3 C=1
A=1 B=3 C=2
A=1 B=3 C=3
etc
For all of the possible values in the list. So the last line should be
A=3 B=3 C=3
Now this should work for abititary sized arrays. So if I have list1 = {1,2,3,4,5,6} list2 = {A,B,C,D,E,F}
I should get
A=1 B=1 C=1 D=1 E=1 F=1
A=1 B=1 C=1 D=1 E=1 F=2
A=1 B=1 C=1 D=1 E=1 F=3
A=1 B=1 C=1 D=1 E=1 F=4
A=1 B=1 C=1 D=1 E=1 F=5
A=1 B=1 C=1 D=1 E=1 F=6
A=1 B=1 C=1 D=1 E=2 F=1
A=1 B=1 C=1 D=1 E=2 F=2
A=1 B=1 C=1 D=1 E=2 F=3
A=1 B=1 C=1 D=1 E=2 F=4
A=1 B=1 C=1 D=1 E=2 F=5
A=1 B=1 C=1 D=1 E=2 F=6
etc
So in the first example there would be 3^3 = 27 combinations and I attempted to solve the problem like:
def printArrays():
letters = {'A', 'B', 'C', 'D', 'E', 'F'}
domain = {1, 2, 3, 4, 5, 6}
myStr = ""
for value in domain:
for letter in letters:
myStr += letter + "=" + str(value) + " "
myStr += "\n"
print(myStr)
Obviously it gives the wrong output since it gives me:
F=1 D=1 C=1 B=1 E=1 A=1
F=2 D=2 C=2 B=2 E=2 A=2
F=3 D=3 C=3 B=3 E=3 A=3
F=4 D=4 C=4 B=4 E=4 A=4
F=5 D=5 C=5 B=5 E=5 A=5
F=6 D=6 C=6 B=6 E=6 A=6
What would be the correct way to solve this problem?
Note: That I would also want a solution that does not involve any libraries as I am trying to learn recursion so a recursive solution would be appreciated.
forloops.{ }. Just use list[]instead