My code is as follows. It loops through blobs which is set of frozenset and check if each blob intersects with mapped which is a set. If a blob does intersects with mapped and also satisfies the condition of being terminal, then add the intersection set to the result.
result = set()
for b in blobs:
mapped_b = b & mapped
if mapped_b and _is_terminal(mapped_b):
result.add(mapped_b)
Can this logic be written in a better way? I was thinking of list comprehension, but since mapped_b is formed on the go, it seems I have to make it multiple times which is wasteful.
[result.add(b&mapped) for b in blobs if b&mapped and _is_terminal(b&mapped)]
Also is it worth the trouble to use filter for the if statement?