Class KeyedSets
source code
This is a collection of named sets. In principal, it contains an
empty set for every name, and you can add things to sets, discard things
from sets, and so on.
>>> ks = KeyedSets()
>>> ks['tim']
set([])
>>> ks.add('tim', 'friendly')
>>> ks.add('tim', 'dexterous')
>>> ks['tim']
set(['friendly', 'dexterous'])
>>> 'tim' in ks
True
>>> 'ron' in ks
False
>>> ks.discard('tim', 'friendly')
>>> ks.pop('tim')
set(['dexterous'])
>>> ks['tim']
set([])
This class is careful to conserve memory space - empty sets do not
occupy any space.