if __name__ == '__main__':
x = int(input())
y = int(input())
z = int(input())
n = int(input())
while True:
print('[', end="")
for i in range(0,x+1):
for j in range(0,y+1):
for k in range(0,z+1):
array=[i,j,k]
if (i+j+k)!=n:
print(array, end=", ")
print(']')
break
It displays output as: [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1], ]
Required output: [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 1]]
How can I delete the last comma?
I have tried using rstrip function inside the loop but it deletes every other comma resulting in answer as: [[0, 0, 0] [0, 0, 1] [0, 1, 0] [1, 0, 0] [1, 1, 1]]