From 7e8d380356703bf8ecef27e8532d7ea1d259fb17 Mon Sep 17 00:00:00 2001 From: faze-geek Date: Fri, 22 Mar 2024 18:33:05 +0530 Subject: [PATCH] Cover subset operators --- python/_set.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/python/_set.py b/python/_set.py index 493bcfec..96eb9daa 100644 --- a/python/_set.py +++ b/python/_set.py @@ -59,6 +59,26 @@ class set: ret.add(elem) return ret + def __lt__(self, other): + if len(self) >= len(other): + return False + for elem in self: + if elem not in other: + return False + return True + + def __le__(self, other): + for elem in self: + if elem not in other: + return False + return True + + def __gt__(self, other): + return other < self + + def __ge__(self, other): + return other <= self + def union(self, other): return self | other @@ -78,10 +98,10 @@ class set: return self.__and__(other).__len__() == 0 def issubset(self, other): - return self.__sub__(other).__len__() == 0 + return self <= other def issuperset(self, other): - return other.__sub__(self).__len__() == 0 + return self >= other def __contains__(self, elem): return elem in self._a