diff --git a/solve/multiset.py b/solve/multiset.py index 9d6afad..e2faf9d 100644 --- a/solve/multiset.py +++ b/solve/multiset.py @@ -1,6 +1,5 @@ from collections import Counter from collections.abc import Iterable, Iterator, Set -from itertools import product from typing import Any, Self @@ -101,8 +100,16 @@ def isdisjoint(self, other: Set, /) -> bool: """ Returns ``True`` if this set and other have no common elements. """ - for _ in product(self, other): - return False + if len(self) < len(other): + shorter = self + longer = other + else: + shorter = other + longer = self + + for e in shorter: + if e in longer: + return False return True