MCPcopy Create free account
hub / github.com/ActiveState/code / Container

Class Container

recipes/Python/574428_Container/recipe-574428.py:7–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#Version :2.4
6import operator
7class Container:
8 def __init__(self,switch): #Initialize
9 self.switch = switch
10 self.value = []
11 for item in switch:
12 self.value.append(item)
13 def append(self,node):
14 return self.value.append(node)
15 def __getattr__(self,name):
16 if name == 'union':
17 self.union = operator.or_
18 return operator.attrgetter(name)
19 elif name == 'intersect':
20 self.intersect = operator.and_
21 return operator.attrgetter(name)
22 else :
23 return getattr(self.value,name)
24 def __getitem__(self,i):
25 return self.switch[i]
26 def __len__(self): # Container length
27 return len(self.switch)
28 def __and__(self,other): # Intersection
29 self.intersect = operator.and_
30 res = []
31 for item in self.switch:
32 if item in other:
33 res.append(item)
34 return Container(res)
35 def __or__(self,other): # Union
36 self.union = operator.or_
37 res = self.value[:]
38 for item in other:
39 if item not in res:
40 res.append(item)
41 return Container(res)
42 def insideout(self,other): # !=Intersection != Union item only in x but not in y
43 res = []
44 for item in self.switch:
45 if item not in other:
46 res.append(item)
47 return Container(res)
48 def outinside(self,other): # != Union != Intersection item in x and y but not in both
49 res = []
50 for item in self.switch:
51 if item not in other:
52 res.append(item)
53 for item in other:
54 if item not in self.switch:
55 res.append(item)
56 return Container(res)
57 def __str__(self): #Print
58 return '<Container : %s \n<Length : %s' % (self.value,(len(self.switch)))
59
60if __name__ == '__main__':
61 X = Container([1,2,3,4,5,6])

Callers 7

__and__Method · 0.70
__or__Method · 0.70
insideoutMethod · 0.70
outinsideMethod · 0.70
recipe-574428.pyFile · 0.70
socks5connectMethod · 0.50
socks4aconnectMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected