I have three tuples, listA
, listB
, and listC
.
It is important that in each list, each value keeps the same index as their initial corresponding values in the other two lists.
I have two conditions, one for listA
and one for listB
. I would like all the values in listA
which don't satisfy the listA
condition remove, and all the values in listB
which don't satisfy the listB conditions removed and so that all the values with the same indices as these removed values in all three lists are also removed.
This will involve removing some values which do satisfy the listA
conditions from listA
etc if listB
condition is not met. So that the result is three lists who's values all indiviudally satisfy their own list's condition (although listC
has no condition) and the values have the same pairing as initially.
I have managed to do it by iterating through the list using a for loop, an example of the way that I did this is shown below, the condition imposed on listA is x<10, and for listB is x>20. I'm aware there are much more elegant and pythonic methods for doing this using zip and filtering however I haven't been able to get them to work thus far. I am not a very experienced programmer so any help would be greatly appreciated.
listA=(15,5,2,8,10,11,4,8)
listB=(19,25,28,14,32,10,21,29)
listC=(0,9,13,4,19,51,83,13)
listAA=[]
listBB=[]
listCC=[]
for i in range(len(listA)):
if listA[i]<10:
if listB[i]>20:
listAA.append(listA[i])
listBB.append(listB[i])
listCC.append(listC[i])
else:
continue
else:
continue
print(listAA,listBB,listCC)