This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients panda1200, rhettinger, serhiy.storchaka
Date 2022-02-10.08:35:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Would not testing len(self.difference(other)) == 0 be more efficient? Making a copy of a set and removing elements one by one may be faster than add elements one by one, because we only need to allocate a single chunk of memory for a set.

It depends on relative values of len(self), len(other) and len(set(other)). For example, the following code may be optimal in some cases:

    tmp = set()
    it = iter(other)
    for item in it:
        # if item in self: ?
        if len(tmp) >= len(self):
            self = self.difference(tmp, it)
            if not self:
                return True
            return not self
        return False  # len(self) > len(set(other))

The disadvantage of such optimizations is that they make the code much more bigger. The current code is small and simple, and good enough in most cases.
Date User Action Args
2022-02-10 08:35:24serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, panda1200
2022-02-10 08:35:24serhiy.storchakasetmessageid: <>
2022-02-10 08:35:24serhiy.storchakalinkissue46705 messages
2022-02-10 08:35:24serhiy.storchakacreate