Python-HackerRank Problem List Comprehensions
Problem 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. Source Code if __name__ == '__main__' : x = int ( input ()) y = int ( input ()) z = int ( input ()) n = int ( input ()) print ([[ a , b , c ] for a in range ( 0 , x+1 ) for b in range ( 0 , y+1 ) for c in range ( 0 , z+1 ) if a + b + c != n ])
Comments
Post a Comment