From 43db0d6a2c5d57c9cd713928f73b993add965b82 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 21 Aug 2002 02:22:08 +0000 Subject: [PATCH] Fast size check for sub/super set tests --- Lib/sets.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/sets.py b/Lib/sets.py index c678bb44943..7b15aa5a012 100644 --- a/Lib/sets.py +++ b/Lib/sets.py @@ -239,6 +239,8 @@ class BaseSet(object): def issubset(self, other): """Report whether another set contains this set.""" self._binary_sanity_check(other) + if len(self) > len(other): # Fast check for obvious cases + return False for elt in self: if elt not in other: return False @@ -247,6 +249,8 @@ class BaseSet(object): def issuperset(self, other): """Report whether this set contains another set.""" self._binary_sanity_check(other) + if len(self) < len(other): # Fast check for obvious cases + return False for elt in other: if elt not in self: return False