Tricky Dictionary Question from newbie

Mark Jackson mjackson at
Mon Jul 11 20:10:26 CEST 2005

"Ric Da Force" <ric at> writes:

> It is hard to explain but this is what I mean:
> Dict = {'rt': 'This is repeated', 'sr': 'This is repeated', 'gf': 'This is 
> not'}
> 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']}

NewDict = {}
for x in Dict.keys():
	except KeyError:
		NewDict[Dict[x]] = [x]

Mark Jackson -
	It is difficult for men in high office to avoid
	the malady of self-delusion.	- Calvin Coolidge

More information about the Python-list mailing list