Sort by

recency

|

1847 Discussions

|

  • + 0 comments

    Here is solution in python - https://programmingoneonone.com/hackerrank-list-comprehensions-solution-in-python.html

  • + 0 comments

    print([[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])

  • + 0 comments

    result = [ [i, j, k] for i in range(x + 1) for j in range(y + 1) for k in range(z + 1) if (s := i + j + k) != n ]

  • + 2 comments
    cuboid = [[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]
    print(cuboid)
    

    But i dont really understand why we made range(x+1) and so on?

  • + 0 comments

    don't forget about itertools in python, it's tremendously powerful:

    from itertools import product
    
    
    if __name__ == '__main__':
        x = int(input())
        y = int(input())
        z = int(input())
        n = int(input())
        
        print(
            [
                [i, j, k] 
                for i, j, k in product(range(x + 1), range(y + 1), range(z + 1)) 
                if i + j + k != n
            ]
        )