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
|
1846 Discussions
|
Please Login in order to post a comment
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?
don't forget about itertools in python, it's tremendously powerful:
if name == 'main': x = int(input()) y = int(input()) z = int(input()) n = int(input())