[issue9212] dict_keys purports to implement the Set ABC, but is missing the isdisjoint method

Daniel Urban report at bugs.python.org
Sat Jul 24 10:04:02 CEST 2010


Daniel Urban <urban.dani+py at gmail.com> added the comment:

> Unless there is a reason I have missed, I would iterate through the
> smaller set, which might even be empty or nearly so, rather than
> either in particular.

You're right, here is a new patch. Pseudocode:

def isdisjoint(self, other):
    if self is other:
        if len(self) == 0:
            return True
        else:
            return False
    else:
        if len(other) > len(self):
            self, other = other, self
        for item in other:
            if item in self:
                return False
        return True

----------
Added file: http://bugs.python.org/file18172/issue9212a.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9212>
_______________________________________


More information about the Python-bugs-list mailing list