Issue
I have a list called "list", which consists of about 20K strings, and I need to remove from it elements which have "text": "" in it.
I'm creating a new clean list like this
clean_list = []
for i in list:
if '"text": ""' in i == False:
clean_list.append(i)
print(i)
But elements don't append and clean_list is empty. What can be the problem? Smth is wrong with the cycle.
How else can I get rid of some elements in the list?
Solution
First, you should not name variables with protected keywords like list.
For your use case you could use list comprehension:
clean_list = [string for string in list if '"text": ""' not in string]
Answered By - nb123 Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.