Implemented <, <=, >, >= for sets, giving subset and proper-subset

meanings.  I did not add new, e.g., ispropersubset() methods; we're
going nuts on those, and, e.g., there was no "friendly name" for
== either.
This commit is contained in:
Tim Peters 2002-08-25 18:43:10 +00:00
parent 93d8d48c15
commit ea76c98014
3 changed files with 45 additions and 12 deletions

View file

@ -275,6 +275,18 @@ class BaseSet(object):
return False
return True
# Inequality comparisons using the is-subset relation.
__le__ = issubset
__ge__ = issuperset
def __lt__(self, other):
self._binary_sanity_check(other)
return len(self) < len(other) and self.issubset(other)
def __gt__(self, other):
self._binary_sanity_check(other)
return len(self) > len(other) and self.issuperset(other)
# Assorted helpers
def _binary_sanity_check(self, other):