Program Statement
– List Comprehension in Python
https://www.hackerrank.com/challenges/list-comprehensions
print a list of all possible coordinates on the three dimensional grid, such that at any point the sum Xi + Yi + Zi is not equal to N.
Solution:- Python 3 Version
https://www.hackerrank.com/challenges/list-comprehensions
print a list of all possible coordinates on the three dimensional grid, such that at any point the sum Xi + Yi + Zi is not equal to N.
Solution:- Python 3 Version
xlist =
range(int(input()) + 1)
ylist =
range(int(input()) + 1)
zlist =
range(int(input()) + 1)
n = int(input())
complst = [[x,y,z]
for x in xlist for y in ylist for z in zlist if x + y + z != n]
print(complst)
Input -
Input -
1
1
2
1
2
Output -
[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
References -
http://www.thelearningpoint.net/computer-science/learning-python-programming-and-data-structures/learning-python-programming-and-data-structures--tutorial-15--generators-and-list-comprehensions
http://www.python-course.eu/list_comprehension.php
[[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
References -
http://www.thelearningpoint.net/computer-science/learning-python-programming-and-data-structures/learning-python-programming-and-data-structures--tutorial-15--generators-and-list-comprehensions
http://www.python-course.eu/list_comprehension.php
Comments