For example, I call this function by passing a dictionary as parameter:
>>> inv_map({\'a\':1, \'b\':2, \'c\':3, \'d\':2}) {1: [\'a\'], 2: [\'b\', \'
You can probably use defaultdict or setdefault here.
defaultdict
setdefault
def invertDictionary(orig_dict): result = {} # or change to defaultdict(list) for k, v in orig_dict.iteritems(): result.setdefault(v, []).append(k)