We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
List Comprehensions
List Comprehensions
Sort by
recency
|
1848 Discussions
|
Please Login in order to post a comment
x = int(input()) y = int(input()) z = int(input()) n = int(input()) array = [] for i in range(x+1): for j in range(y+1): for k in range(z+1): if i+j+k != n: array.append([i,j,k]) print(array)
Here is solution in python - https://programmingoneonone.com/hackerrank-list-comprehensions-solution-in-python.html
print([[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])
result = [ [i, j, k] for i in range(x + 1) for j in range(y + 1) for k in range(z + 1) if (s := i + j + k) != n ]
But i dont really understand why we made range(x+1) and so on?