list comprehension python 3 hackerrank solution

x, y, z, n = int(input()), int(input()), int(input()), int(input())
print ([[a,b,c] for a in range(0,x+1) for b in range(0,y+1) for c in range(0,z+1) if a + b + c != n ])

Here is what the above code is Doing:
1. It’s creating a list of lists.
2. It’s iterating over the range of x, y, and z.
3. It’s creating a list of all possible combinations of x, y, and z.
4. It’s filtering out all the combinations that don’t sum to n.
5. It’s printing the list of lists.