File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ URL : https://www.hackerrank.com/challenges/list-comprehensions/problem?isFullScreen=true
3+ Question : Let's learn about list comprehensions! You are given three integers and representing the dimensions of a cuboid along with an integer .
4+ Print a list of all possible coordinates given by on a 3D grid where the sum of is not equal to . Here, .
5+ Please use list comprehensions rather than multiple loops, as a learning exercise. (View Full From 🔗 URL )
6+
7+
8+ """
9+
10+
11+ if __name__ == '__main__':
12+ x = int(input())
13+ y = int(input())
14+ z = int(input())
15+ n = int(input())
16+
17+ # Tradition Method
18+ result=[]
19+ # for i in range(x+1):
20+ # for j in range(y+1):
21+ # for k in range(z+1):
22+
23+ # if (i+j+k) != n:
24+ # result.append([i,j,k])
25+ # print(result)
26+
27+ #List Comprehension Method
28+ # result= [[[for k in range(z+1)]] [for j in range(y+1)] for i in range(x+1) if (i+j+k) != n ]
29+ result=[ [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]
30+ print(result)
You can’t perform that action at this time.
0 commit comments