I wish to first loop from the delete list for word "man" then "eater". Compare these words with the strings within the item_list. If matched, then ignore it and if not match then append to "a".
it should ignore the any words that are matched with the "man" and "eater". Somehow, My output should be ignoring the list of strings that contain words "man" and "eater" but somehow it just keep looping for the first and second word in delete. Example, when it loop word for "man" it properly deleted the list of strings that are matched with this word, but then when it loop for word "eater", it started to find again from the item_list(2nd time) and then reappend again a new set of strings. This makes everything becoming very wrong.
My code:
item = []
delete=["man", "eater"]
item_list = ['sharper_task|$none_venue|man', 'sharper_task|man_venue|king', 'sharper_task|king_venue|world', 'sharper_task|world_venue|dont', 'sharper_task|を_venue|eater', 'sharper_task|eater_venue|todo', 'sharper_task|todo_venue|,']
a = [[] for i in range(len(item_list))]
if delete is not None:
for dele in delete:
for ii, f in enumerate(item_list):
if dele not in f:
a[ii].append(f)
else:
a = [[nn] for nn in item_list]
item.append(a)
print(item)
Current output:
[[['sharper_task|$none_venue|man'], ['sharper_task|man_venue|king'], ['sharper_task|king_venue|world', 'sharper_task|king_venue|world'], ['sharper_task|world_venue|dont', 'sharper_task|world_venue|dont'], ['sharper_task|を_venue|eater'], ['sharper_task|eater_venue|todo'], ['sharper_task|todo_venue|,', 'sharper_task|todo_venue|,']]]
Expected output:
['sharper_task|king_venue|world', 'sharper_task|world_venue|dont', 'sharper_task|todo_venue|,']
I think this might be tough but if possible, I wish to stick with a shorter codes and not to include too many for loops here. I am still learning and I found out that I used too many for loops when iterating a list.