-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseful.py
More file actions
executable file
·34 lines (29 loc) · 996 Bytes
/
Copy pathuseful.py
File metadata and controls
executable file
·34 lines (29 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class SetDict (dict) :
"""Dictionary of Sets"""
def insert(self,key,val) :
"""Add an item to the set stored at key"""
if not self.has_key(key) :
self[key] = set([])
self[key].add(val)
def contains(self,x,y=None) :
""" If two arguments are given, see if item y is in the set stored at x.
If only one argument, x, is given, see if it occurs in any of the sets
"""
if not (y is None) :
return y in self[x]
for k in self.keys() :
if x in self[k] :
return True
return False
def pp(self,file=None) :
"Pretty Print"
for key in self.iterkeys() :
if file :
file.write("\n: %s\n"%key)
else :
print "\n:",key
for x in self[key] :
if file :
file.write("%s "%x)
else :
print x,