mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
some change
This commit is contained in:
parent
60aa4fe93d
commit
665fb04b8f
File diff suppressed because one or more lines are too long
@ -2,15 +2,13 @@ class set:
|
|||||||
def __init__(self, iterable=None):
|
def __init__(self, iterable=None):
|
||||||
iterable = iterable or []
|
iterable = iterable or []
|
||||||
self._a = {}
|
self._a = {}
|
||||||
for item in iterable:
|
self.update(iterable)
|
||||||
self.add(item)
|
|
||||||
|
|
||||||
def add(self, elem):
|
def add(self, elem):
|
||||||
self._a[elem] = None
|
self._a[elem] = None
|
||||||
|
|
||||||
def discard(self, elem):
|
def discard(self, elem):
|
||||||
if elem in self._a:
|
self._a.pop(elem, None)
|
||||||
del self._a[elem]
|
|
||||||
|
|
||||||
def remove(self, elem):
|
def remove(self, elem):
|
||||||
del self._a[elem]
|
del self._a[elem]
|
||||||
@ -18,10 +16,9 @@ class set:
|
|||||||
def clear(self):
|
def clear(self):
|
||||||
self._a.clear()
|
self._a.clear()
|
||||||
|
|
||||||
def update(self,other):
|
def update(self, other):
|
||||||
for elem in other:
|
for elem in other:
|
||||||
self.add(elem)
|
self.add(elem)
|
||||||
return self
|
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self._a)
|
return len(self._a)
|
||||||
@ -37,19 +34,13 @@ class set:
|
|||||||
|
|
||||||
def __or__(self, other):
|
def __or__(self, other):
|
||||||
ret = self.copy()
|
ret = self.copy()
|
||||||
for elem in other:
|
ret.update(other)
|
||||||
ret.add(elem)
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def __xor__(self, other):
|
def __xor__(self, other):
|
||||||
ret = set()
|
_0 = self - other
|
||||||
for elem in self:
|
_1 = other - self
|
||||||
if elem not in other:
|
return _0 | _1
|
||||||
ret.add(elem)
|
|
||||||
for elem in other:
|
|
||||||
if elem not in self:
|
|
||||||
ret.add(elem)
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def union(self, other):
|
def union(self, other):
|
||||||
return self | other
|
return self | other
|
||||||
|
Loading…
x
Reference in New Issue
Block a user