I was recently solving some questions on hacker rank when I came across a question where we had a list of lists and we have to remove the list whose sum of elements is 2(in my case). Input was 1 1 1 2 and the original list generated was [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]] so according to the my code the sub lists of [0, 1, 1],[1, 0, 1], [1, 1, 0] should be removed but the output I was getting is [[0, 0, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 1, 0], [1, 1, 1]] . Can someone please explain why the sub list of [1, 1, 0] is still present. Here is the code:
if __name__ == '__main__':
x = int(input())
y = int(input())
z = int(input())
n = int(input())
lists = []
for i in range(x+1):
for j in range(y+1):
for k in range(z+1):
lists.append([int(i), int(j), int(k)])
print(lists)
for list in lists:
value = list[0] + list[1] + list[2]
if value == n:
print(list)
lists.remove(list)
print(lists)