and b. I want to delete all the numbers in list b where there is a '0' as well as the corresponding numbers in a that share the same index with the zeroes in b. This is my code:
a = [ 1 , 23 , 3 , 45 , 5 , 63 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15] b = [ 8 , 0 , 0 , 7 , 0 , 9 , 3 , 2 , 4 , 13 , 25 , 45 , 34 , 25 , 11] indexzeroes = [i for i, j in enumerate(b) if j == 0] for i in indexzeroes: b.pop(i) a.pop(i) print a print b However I get the wrong updated lists for a and b. I've identified the reason as being that in the 'for loop' I've changed the list structure each time I 'pop' an item so that the indexes with the remaining zeroes in change also.
This seems so convoluted for such a ostensibly simple problem. Can anyone help?