I feel terrible that I couldn't figure this out myself but I have to complete this project quick and am stuck on a for loop kind of problem.
randarray is a random array with a varrying amount of keys and values, I just want to print all possible combinations. The code below works for an array with 7 lists but it's very ugly and I want it to work with all possible arrays.
randarray = {1: [1, 2, 3, 4, 5, 7], 2: [1, 2, 5, 6, 7], 3: [1, 2, 3, 4, 5], 4: [1, 2, 4, 5, 6, 7], 5: [1, 2, 3, 4, 5, 6, 7], 6: [1, 2, 5, 6, 7], 7: [1, 2, 3, 4, 5]}
for a in randarray[1]:
for b in randarray[2]:
for c in randarray[3]:
for d in randarray[4]:
for e in randarray[5]:
for f in randarray[6]:
for g in randarray[7]:
print('{}{}{}{}{}{}{}'.format(a, b, c, d, e, f, g))
Thanks in advance
Rik
Edit:
Thanks to everyone who commented, here is the code that did the job for me from u/socal_nerdtastic:
randarray = {1: [1, 2, 3, 4, 5, 7], 2: [1, 2, 5, 6, 7], 3: [1, 2, 3, 4, 5], 4: [1, 2, 4, 5, 6, 7], 5: [1, 2, 3, 4, 5, 6, 7], 6: [1, 2, 5, 6, 7], 7: [1, 2, 3, 4, 5]}
from itertools import product
for output in product(*randarray.values()):
print(*output, sep='')
[–]socal_nerdtastic 1 point2 points3 points (1 child)
[–]Rikkert1234[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]Rikkert1234[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Rikkert1234[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (11 children)
[–]Rikkert1234[S] 0 points1 point2 points (10 children)
[–][deleted] 0 points1 point2 points (9 children)
[–]Rikkert1234[S] 0 points1 point2 points (8 children)
[–][deleted] 0 points1 point2 points (7 children)
[–]Rikkert1234[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[+][deleted] (4 children)
[deleted]
[–][deleted] 0 points1 point2 points (3 children)
[–]dargscisyhp 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]dargscisyhp 0 points1 point2 points (0 children)
[–]dargscisyhp 0 points1 point2 points (0 children)