Check if list items contains substrings from another list

后端 未结 4 1706
梦毁少年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 09:59

    some_list=['abc-123', 'def-456', 'ghi-789', 'abc-456']
    bad = ['abc', 'def']
    for i in range (0,len(bad)):
        if bad[i] in some_list:
            print('Found a bad entry:', bad[i])
    

提交回复
热议问题