Skip to content

Commit 576df61

Browse files
authored
List Comprehension From HackerRank | Python Code
1 parent 6a407c7 commit 576df61

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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)

0 commit comments

Comments
 (0)