You can use any
:
list1 = ['bj-100-cy','bj-101-hd','sh-200-pd','sh-201-hp']
list2 = [100, 200]
list2 = [str(x) for x in list2]
outcome = [s for s in list1 if any(x in s for x in list2)]
any
returns True
if any of the conditions you give it are True
.
manpreet
Best Answer
2 years ago
I have two lists looking like:
I want to substring filter
list1
by elements oflist2
and get expected output as follows:When doing:
I get a result like this:
['[', '1', '0', '0', ',', ' ', '2', '0', '0', ']']
. How can I filter it correctly?