Sha256: 6aa90fcf4435916485f68e79177646506fa2f3d206e8ccbde797b63950d290a5

Contents?: true

Size: 1.1 KB

Versions: 83

Compression:

Stored size: 1.1 KB

Contents

class CustomSet(object):
    def __init__(self, elements=[]):
        self.elements = list(elements)

    def isempty(self):
        return not self.elements

    def __iter__(self):
        return iter(self.elements)

    def __contains__(self, element):
        return element in self.elements

    def issubset(self, other):
        return all(x in other for x in self)

    def isdisjoint(self, other):
        return all(x not in other for x in self)

    def __eq__(self, other):
        return self.issubset(other) and other.issubset(self)

    def add(self, element):
        if element not in self:
            self.elements.append(element)

    def intersection(self, other):
        result = CustomSet()
        for x in self:
            if x in other:
                result.add(x)
        return result

    def __sub__(self, other):
        result = CustomSet()
        for x in self:
            if x not in other:
                result.add(x)
        return result

    def __add__(self, other):
        result = CustomSet(self.elements)
        for x in other:
            result.add(x)
        return result

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.179 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.178 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.177 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.176 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.175 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.174 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.173 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.172 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.171 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.170 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.169 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.167 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.166 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.165 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.164 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.163 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.162 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.161 tracks/python/exercises/custom-set/example.py
trackler-2.2.1.160 tracks/python/exercises/custom-set/example.py