I'm looking for a way to completely delete an element from a tuple based on a condition in Python. The following is a subsection of my code. If it's possible I would like the solution to do its thing in the third if-clause to keep the structure of my main code.
Here is my code:
import ast
data = []
myList=[0,"[('AA', 'BB'), ('CC', 'DD'), ('EE', 'FF'), ('GG', 'HH')]"]
for a in ast.literal_eval(myList[1]):
Value = a[0]
Type = a[1]
if(Type == "BB"):
Value="XX"
if(Type == "DD"):
Value="YY"
if(Type == "FF"):
Value=""
data.append([myList[0], Value])
print(data)
Current Output:
[[0, 'XX'], [0, 'YY'], [0, ''], [0, 'GG']]
What I need:
[[0, 'XX'], [0, 'YY'], [0, 'GG']]