blueloveTH 1 rok temu
rodzic
commit
665fb04b8f
2 zmienionych plików z 7 dodań i 16 usunięć
  1. 0 0
      include/pocketpy/_generated.h
  2. 7 16
      python/_set.py

Plik diff jest za duży
+ 0 - 0
include/pocketpy/_generated.h


+ 7 - 16
python/_set.py

@@ -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.add(item)
+        self.update(iterable)
 
 
     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:
-            del self._a[elem]
+        self._a.pop(elem, None)
 
 
     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.add(elem)
+        ret.update(other)
         return ret
         return ret
 
 
     def __xor__(self, other): 
     def __xor__(self, other): 
-        ret = set() 
-        for elem in self: 
-            if elem not in other: 
-                ret.add(elem) 
-        for elem in other: 
-            if elem not in self: 
-                ret.add(elem) 
-        return ret
+        _0 = self - other
+        _1 = other - self
+        return _0 | _1
 
 
     def union(self, other):
     def union(self, other):
         return self | other
         return self | other

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików