Tricky Dictionary Question from newbie

Ric Da Force ric at
Mon Jul 11 19:54:07 CEST 2005

Hi all,

I have a dictionary containing about 300 items, some of the values being 
repeated.  Both keys and values are strings.  How can I turn this thing on 
its head so that we create a key based on each unique value and build the 
values based on the keys corresponding to the repeated values?

It is hard to explain but this is what I mean:

Dict = {'rt': 'This is repeated', 'sr': 'This is repeated', 'gf': 'This is 

I want this to return a new dict with string keys and lists containing the 
previous keys for repeated values.

NewDict = {'This is repeated':['rt','sr'],'This is not':['gf']}

I am still learning Python and have struggled with this for hours before 
deciding to go for help.  Unfortunately, I didn't really know how to search 
for this in google and decided to post it here.  I apologise if this is too 
basic for this newsgroup...


More information about the Python-list mailing list