I have a dictionary with almost 100,000 (key, value) pairs and the majority of the keys map to the same values. For example:
mydict = {\'a\': 1, \'c\': 2, \'
for k,v in dict.iteritems(): try: reversed_dict[v].append(k) except KeyError: reversed_dict[v]=[k]