Using multiple NOT IN statements with Python
问题 I need to URLs with three specific specific substrings out of a loop. The following code worked, but I am sure there's a more elegant way to do it: for node in soup.findAll('loc'): url = node.text.encode("utf-8") if "/store/" not in url and "/cell-phones/" not in url and "/accessories/" not in url: objlist.loc.append(url) else: continue Thank you! 回答1: url = node.text.encode("utf-8") sub_strings = ['/store','/cell-phones/','accessories'] if not any(x in url for x in sub_strings): objlist.loc