Given the following data:
a = ["onee", "two", "three"]
b = ["one", "four"]
I would like for some test such as the following:
[True if x in a else False for x in b]
To return
[True, False]
Instead of
[False, False]
So for each element in list b, I want to see whether it's a substring of any of the elements in list a.
One way this can be done is as following:
test = []
for elb in b:
included = False
for ela in a:
if elb in ela:
included = True
break
test.append(included)
I don't feel that this is a very nice approach though, perhaps there's a comprehension that can improve on it?
The following also works:
[True if any(elb in ela for ela in a) else False for elb in b]
I'm just thinking that there's likely to be a nicer approach.
This is enough: