Re: Restructure dictionary (Python 2.5)

2009-03-02 Thread imageguy
> ... this is a crappy solution that's underusing Python. Please > enlighten me of a better way! > > - Fencer One thing that springs to mind is using the dict method .setdefault for dkey, vallist in old_dict.iteritems(): for val in vallist: new_dict.setdefault(val, set()).add(dkey)

Re: Restructure dictionary (Python 2.5)

2009-03-02 Thread Tim Chase
I tried this code: old_dict = {'xyz':['a','b','c'],'baz':['c','d']} new_dict = {} for dkey, vallist in old_dict.iteritems(): for val in vallist: if val in new_dict: theset = new_dict[val] theset.add(dkey)