I am trying to write a program that removes lists with "errors" from the nest and in result creates a bad list and a good list: for some reason the loop only executes once leaving a incorrect list
def cool(axe):
infile = open(axe, "r")
holder = []
bad = []
for line in infile:
x = line.strip("\n").split("\t")
for i in range(len(x)):
if x[i].isdigit() == True:
x[i] = int(x[i])
holder.append(x)
#print(holder)
for m in holder:
#print(m)
if "ERROR" in m:
bad.append(m)
for n in holder:
if n in holder and n in bad:
holder.remove(n)
for n in range(len(holder) - 1):
if "ERROR" in holder[n]:
del holder[n]
print(bad)
print(holder)
return holder
print(cool("testin.txt"))
this returns
[['CAMDEN', 'VINCENT', 'Heavy', 68, 93, 'ERROR', 52, 93, 96], ['CAROLINE', 'MCCARTHY', 'Heavy', 'ERROR', 53, 97, 82, 56, 51]]
this is the bad list that prints, which is correct.
[['MAGGIE', 'BLANCO', 'Heavy', 53, 31, 58, 76, 67, 93], ['BENJAMIN', 'KIM', 'Significant', 77, 57, 42, 45, 64, 78], ['JACOB', 'BOLEN', 'Significant', 86, 76, 65, 91, 80, 64], ['CAROLINE', 'MCCARTHY', 'Heavy', 'ERROR', 53, 97, 82, 56, 51]]
this is inteded to be the good list, however does not fully get rid of the error lists
[['MAGGIE', 'BLANCO', 'Heavy', 53, 31, 58, 76, 67, 93], ['BENJAMIN', 'KIM', 'Significant', 77, 57, 42, 45, 64, 78], ['JACOB', 'BOLEN', 'Significant', 86, 76, 65, 91, 80, 64], ['CAMDEN', 'VINCENT', 'Heavy', 68, 93, 'ERROR', 52, 93, 96], ['CAROLINE', 'MCCARTHY', 'Heavy', 'ERROR', 53, 97, 82, 56, 51]]
this is the original lists