def _get_prefix_unrename_dict(self, formula, prefix, filter=""): from iegen.util import invert_dict # Build a new dictionary containing only those (k,v) pairs whose key contains the given filter string dict = invert_dict(self._get_prefix_rename_dict(formula, prefix)) new_dict = {} for k in dict: try: k.index(filter) new_dict[k] = dict[k] except: pass return new_dict
def testInvertMultipleItems(self): from iegen.util import invert_dict dict=invert_dict({'a':3,6:'d','c':10.3}) dict_res={3:'a','d':6,10.3:'c'} self.failUnless(dict_res==dict,'%s!=%s'%(dict_res,dict))
def testInvertOneItem(self): from iegen.util import invert_dict self.failUnless({1:3}==invert_dict({3:1}),'invert_dict({3:1})!={1:3}: %s'%(invert_dict({3:1}))) self.failUnless({'a':3}==invert_dict({3:'a'}),"invert_dict({3:'a'})!={'a':3}: %s"%(invert_dict({3:'a'}))) self.failUnless({'b':'a'}==invert_dict({'a':'b'}),"invert_dict({'a':'b'})!={'b':'a'}: %s"%(invert_dict({'a':'b'})))