2
3 """
4 Mix-in for sets. You must define __iter__, add, remove
5 """
6
8 length = 0
9 for item in self:
10 length += 1
11 return length
12
14 for has_item in self:
15 if item == has_item:
16 return True
17 return False
18
20 for item in other:
21 if item not in self:
22 return False
23 return True
24
25 __le__ = issubset
26
28 for item in self:
29 if item not in other:
30 return False
31 return True
32
33 __ge__ = issuperset
34
37
39 new = self.copy()
40 new |= other
41 return new
42
45
47 new = self.copy()
48 new &= other
49 return new
50
53
55 new = self.copy()
56 new -= other
57 return new
58
61
63 new = self.copy()
64 new ^= other
65 return new
66
69
71 for item in other:
72 self.add(item)
73
75 self.update(other)
76 return self
77
79 for item in self:
80 if item not in other:
81 self.remove(item)
82
86
88 for item in other:
89 if item in self:
90 self.remove(item)
91
95
97 for item in other:
98 if item in self:
99 self.remove(item)
100 else:
101 self.add(item)
102
106
108 try:
109 self.remove(item)
110 except KeyError:
111 pass
112
114 for item in list(self):
115 self.remove(item)
116