HackerRank Python Problem No5 || List Comprehension

preview_player
Показать описание
List Comprehensions

Let's learn about list comprehensions! You are given three integers X, Y and Z representing the dimensions of a cuboid along with an
integer N. You have to print a list of all possible coordinates given by (i, j, k) on a 3D grid where the sum of i + j + k is not
equal to N.

Here, 0 less than or equal to i less than or equal X;
0 less than or equal j less than or equal Y;
0 less than or equal k less than or equal Z

Input Format
Four integers X, Y, Z and N each on four separate lines, respectively.

Constraints
Print the list in lexicographic increasing order.

Sample Input
1
1
1
2

Sample Output
[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
Рекомендации по теме
Комментарии
Автор

I have been trying to understand this since morning, but it was beyond my comprehension. Thank you for your help; now my concept is clear because of you. Thanks Bhanu

Meharhusnain
Автор

Thanks bro i was trying to do the same thing, only thing i didnt that we can use for multiple times here .

abhinandanbhardwaj
Автор

Kindly explain further l don't get the concept you are putting across

ama
Автор

if __name__ == '__main__':
x = int(input())
y = int(input())
z = int(input())
n = int(input())
lis_result=[
[i, j, k]
for i in range(0, x+1)
for j in range(0, y+1)
for k in range(0, z+1)
if i+z+k!=n]
print(lis_result)
#still i am getting error

harjeetsinghkainth
welcome to shbcf.ru