for p in d.items(): ... key = p[0] ... value = p[1] ... if value not in ldoc: ... ldoc[value] = [key] ... else: ... ldoc[value].append(key) ... >>> print ldoc {1: ['orange', 'orange'], 2: ['pear', 'berry', 'pear', 'berry'], 3: ['cherry', 'apple', 'cherry', 'apple']} >>> ldoc.clear() >>> ldoc {} >>> def revdictionary(d): ... rev = {} ... return rev ... >>> print revdictionary(d) {} >>>