Check if list items contains substrings from another list

后端 未结 4 1701
梦毁少年i
梦毁少年i 2020-11-29 09:28

I have a lists:

my_list = [\'abc-123\', \'def-456\', \'ghi-789\', \'abc-456\', \'def-111\', \'qwe-111\']

bad = [\'abc\', \'def\']

and want

4条回答
  •  爱一瞬间的悲伤
    2020-11-29 10:02

    some_list = ['abc-123', 'def-456', 'ghi-789', 'abc-456']
    bad = ['abc', 'def']
    for s in some_list:
        for item in bad:
           if item in s:
              print 'Found ', s
    

    It's simple, works fine and fast( only if your list is not very big.)

提交回复
热议问题