M
M
mikitos592021-10-29 12:58:57
Python
mikitos59, 2021-10-29 12:58:57

How to remove an element from a list whose part is in another list?

There are lists:

list = ['text 1', 'text 2', 'text 3' , 'text 4']
list2 = ['1', '2']

How to make pirnt give out:
text3
text4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2021-10-29
@mikitos59

list1 = ['text 1', 'text 2', 'text 3' , 'text 4']
list2 = ['1', '2']
[x for x in list1 if not any([y in x for y in list2])]
# ['text 3', 'text 4']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question