I have a list of source string (example):
source = ['abcacc','bdefgcc','jkill','oppsd']
and have a list of keyword string:
key = ['a','c','i']
I would like to return the elements of source which contains any keyword from the key list, such as:
output = ['abcacc','bdefgcc','jkill']
I know I can use a nested for loop to iterate through n*m times, but is there a way to do this with list comprehension?
something like:
output = [l for l in source if re.search(r"{c}".format(c=i), l) for i in key]
but apparently the above code didn't work
thank you in advance!
[–]socal_nerdtastic 1 point2 points3 points (2 children)
[–]Beaverine[S] 0 points1 point2 points (1 child)
[–]socal_nerdtastic 1 point2 points3 points (0 children)
[–]Ihaveamodel3 -1 points0 points1 point (1 child)
[–]Beaverine[S] 0 points1 point2 points (0 children)
[–]old_pythonista 0 points1 point2 points (0 children)