ARTICLE AD BOX
i have multiple lists of a bunch of strings gathered indiscriminately. i want to remove any that are unsuitable based on various criteria.
import re asdf = ["apple", "dreamy", "ice", "pencil", "cats", "bell"] list2 = ["cats", "dogs"] for item in asdf: if "a" in item: asdf.remove(item) if item in list2: asdf.remove(item) list2.remove(item) if re.search("[n-z]", item): asdf.remove(item) print(asdf) // ideal result: ["ice", "bell"]this throws an error because it tries to remove the same item multiple times. if it hadn't, it would remove the wrong items since the length of the list changes.
this is a much-simplified version of the real code, but it's a fair idea of how varied the criteria are. it doesn't need to use remove(), but i'm concerned anything other than a series of if statements won't work right for every criterion.
