I often find myself wanting to test the intersection of two sets without using the result of the intersections.
set1 = set([1,2])
set2 = set([2,3])
if(set1 & set2):print("Non-empty intersection")
else:print("Empty intersection")
The problem is that a new set is created to do this test which can be inefficient.
Is there a short way to do this without explicitly writing it out (as in the following)?
if(any(x in set2 for x in set1)):print("Non-empty intersection")
else:print("Empty intersection")