Python 如果行未从列表中的项目开始

Python 如果行未从列表中的项目开始,python,Python,我想知道如何从一个列表中提取那些项目,而不是像另一个列表中的一些项目那样开始 我想做一些像: list_results = ['CONisotig124', '214124', '2151235', '235235', 'PLEisotig1235', 'PLEisotig2354', '12512515', 'CONisotig1325', '21352'] identifier_list=['CON','VEN','PLE'] for item in list_results: i

我想知道如何从一个列表中提取那些项目,而不是像另一个列表中的一些项目那样开始

我想做一些像:

list_results = ['CONisotig124', '214124', '2151235', '235235', 'PLEisotig1235', 'PLEisotig2354', '12512515', 'CONisotig1325', '21352']

identifier_list=['CON','VEN','PLE']


for item in list_results:
  if not item.startswith(     "some ID from the identifier_list"     ):
      print item
那么,我怎么说:

if not item.startswith(     "some ID from the identifier_list"     ):
可以对字符串的元组进行测试:

前缀也可以是要查找的前缀元组

将其与列表一起使用:

identifier_list = ('CON', 'VEN', 'PLE')  # tuple, not list

[elem for elem in list_results if not elem.startswith(identifier_list)]
演示:


这很直截了当,你几乎做到了:

for item in list_results:
  bad_prefix = False
  for id in identifier_list:
    if item.startswith(id):
      bad_prefix = True
      break

  if not bad_prefix:
    print item

列表中的另一个for循环可以实现这一点
for item in list_results:
  bad_prefix = False
  for id in identifier_list:
    if item.startswith(id):
      bad_prefix = True
      break

  if not bad_prefix:
    print item