Problem Name: Python - List Comprehensions

Problem Link:

In this HackerRank Functions in PYTHON problem solution,

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.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 < = i <= x; 0 <= j <= y ; 0 <= k <= z Please use list comprehensions rather than multiple loops, as a learning exercise.


x = 1

y = 1

z = 2

n = 3

All permutations of [i,j,k] are:


Print an array of the elements that do not sum to n = 3.




Code Examples

#1 Code Example with Python Programming

Code - Python Programming

from itertools import product
if __name__ == '__main__':
    x = int(input())
    y = int(input())
    z = int(input())
    n = int(input())
    xd = [i for i in range(x+1)]
    yd = [i for i in range(y+1)]
    zd = [i for i in range(z+1)]
    print([list(x) for x in product(xd,yd,zd) if sum(x)!=n])
Copy The Code & Try With Live Editor


[Solved] Print Function in PYTHON solution in Hackerrank
[Solved] Find the Runner-Up Score! in PYTHON solution in Hackerrank