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
|
1779 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])
if name == 'main': x = int(input()) y = int(input()) z = int(input()) n = int(input())
I tried this
list = [[i,j,k] for i in range(0,x+1) for j in range(0,y+1) for k in range(0,z+1)] list2=[] for i in range (0,len(list)): if sum(list[i]) !=n: list2.append(list[i]) print(list2)
I was stuck on a coding problem about list comprehensions, but a friend who works in commercial repairing services in London explained it with a real-world analogy now it finally makes sense!
comb = [[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]