Let's say I have a list of lists, e.g:
my_list = [['ab', 'bc'], ['cd', 'de'], ['ef', 'fg'], ['gh', 'hi']]
I then have a list of no-go words, e.g:
no_go_list = ['ab', 'fg']
What I would like to do is to get a list, where it checks if at least one of the items in the no_go_list
is in one of the lists in my_list
, so the result should just be:
final_list = [['cd', 'de'], ['gh', 'hi']]
I was thinking about doing it like this:
final_list = [l for l in my_list if not no_go_list in l]
But this checks if both of the no_go_list
items present. So I am guessing this needs some modification, I just can't seem to figure out how.
question from:
https://stackoverflow.com/questions/65894275/check-if-one-item-in-a-list-is-in-a-list-of-lists 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…