mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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:
parent
93d8d48c15
commit
ea76c98014
3 changed files with 45 additions and 12 deletions
12
Lib/sets.py
12
Lib/sets.py
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue