'Python abbreviated string record [duplicate]

Can anyone explain to me how another way to write ans. I don't know how it works written in one line.

X = int(raw_input())
Y = int(raw_input())
Z = int(raw_input())
N = int(raw_input())
ans = [[i, j, k] for i in range(X + 1) for j in range(Y + 1) for k in range(Z + 1) if i + j + k != N]
print ans


Solution 1:[1]

I think this is what you meant:

X = int(raw_input())
Y = int(raw_input())
Z = int(raw_input())
N = int(raw_input())
ans = []

for i in range(X + 1):
    for j in range(Y + 1):
        for k in range(Z + 1):
            if i + j + k != N:
                ans.append([i, j, k])
print ans

Please correct me if I'm wrong

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eilonlif