You may use a nested list comprehension expression using zip()
and enumerate()
to filter the content as:
>>> a = [[0, 1, 1, 2], [0, 5, 0, 0], [2, 0, 3, 3]]
>>> remove_a_index = [[0], [0, 2, 3], [1]]
>>> a = [[j for i, j in enumerate(x) if i not in y] for x, y in zip(a, remove_a_index)]
# where new value of `a` will be:
# [[1, 1, 2], [5], [2, 3, 3]]
Based on your desired result, in case if you just want to remove zeroes from the a
list then you don't need the intermediate remove_a_index
list. You may use a list comprehension expression to skip the zeroes from the new list as:
>>> a = [[0, 1, 1, 2], [0, 5, 0, 0], [2, 0, 3, 3]]
>>> [[j for j in i if j!=0] for i in a]
[[1, 1, 2], [5], [2, 3, 3]]