range is actually a semi-closed function. Thus, the final value will not be included in the resulting range.
If X = 2, the possible values โโof Xi can be 0, 1, and 2
In your code, range(X) will only return 0 and 1 if X is 2. You should have used range(X + 1) .
X, Y, Z, N = 1, 1, 1, 2 [[x,y,z] for x in range(X + 1) for y in range(Y + 1) for z in range(Z + 1) if x+y+z != N] [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
You can write the same thing with itertools.product like this
X, Y, Z, N = 1, 1, 1, 2 from itertools import product [list(i) for i in product(range(X + 1), range(Y + 1), range(Z + 1)) if sum(i) != N] [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]