I am trying to replace a string with another string in a list, but failed and I don't know why.
For example, I have a list:
predicts =
[['__label__1'],
['__label__0'],
['__label__1'],
['__label__1'],
['__label__0'],
['__label__1']]
i want to replace __label__1 with "OK" and __label__0 with "NOT OK" and save it in different variable using :
pred_label = []
for i in predicts:
if i == '__label__1':
pred_label.append("OK")
else:
pred_label.append("NOT OK")
but it failed to replace any of it
predictandpredictsvariable in your code, choose one orpredictsis considered as empty in the second part of your code.predicts = [["OK"] if item[0] is "__label__1" else ["NOT OKE"] for item in predicts]