Maybe this? I should say that this works in python 3.6.
The following code creates a list of tuples from the elements of 'lstA' and 'lstB' excluding the tuple that would contain the offending element. The zip(*[])
unpacks the list and then zips the resulting tuples thus creating the desired groups. Please see this example:
l = [('a', 1), ('b', 2)]
# the star operator is doing the job of the following two lines
# it could be: l1, l2 = [*l]
l0 = l[0]
l1 = l[1]
print(list(zip(l0,l1)))
Then the list() converts the tuples to lists.
Here is the code:
lstA = ['good','good2', '']
lstB = [1,2,3]
lstA, lstB = list(zip(*[(st, lstB[idx]) for idx, st in enumerate(lstA) if st != '']))
Or you can just change the line that creates 'lstB' in your code.
The difference here is the use of enumerate()
which gives as the index of each element of 'lstA'. As the elements that you want to keep have the same index in both lists, we keep the elements of 'lstB' that correspond to the elements of 'lstA' and are not the undesirable empty string ''.
lstA = ['good','good2', '']
lstB = [1,2,3]
lstB = [lstB[idx] for idx, st in enumerate(lstA) if st != '']
lstA = [st for st in lstA if st != '']