Loop for all possible combinations from 3 variables

Question:

I have a bit of code that runs some stats for a moving 3D window at varying size. I have created a loop to to do this in increments of 5 from 5 to 50 as below.

For example first X = 5, Y = 5, Z = 5, then X = 10, Y = 10, z = 10 etc.

This works fine, but what I’d like to do is run the loop with every possible combination of X, Y and Z in increments of 5.

For example

X  Y  Z
5  5  5
10 5  5
15 5  5
.. .. ..
50 5  5
5  10 5
5  15 5
5  20 5
.. .. ..
10 10 5
10 15 5

etc,

so all in all it would be 1000 possible combinations I think

Can i do this with something like itertools.permutations?

I’m pretty new to python and coding so help would be much appreciated

#python code
sizeX = (0)
sizeY = (0)
sizeZ = (0)
count = (0)

for i in range(0,10):
 count = (count + 1)           
 sizeX = (sizeX + 5)
 sizeY = (sizeY + 5)
 sizeZ = (sizeZ + 5) 

#run the code
Asked By: georich

||

Answers:

If you know you will have 3 variables for certain, you can use nested for loops with range:

for i in range(5, 55, 5):
    for j in range(5, 55, 5):
        for k in range(5, 55, 5):
            print(i, j, k)
Answered By: N Chauhan
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.