def invert_dict(d):
 if isinstance(d, dict):
  temp = d
 else:
  temp = dict(d)
 result = {}
 for (key, val) in temp.iteritems():
  if (val not in result):
   result[val] = []
  result[val].append(key)
 return result

def invert_dict ( d ) : if isinstance ( d , dict ) : temp = d else : temp = dict ( d ) result = { } for ( key , val ) in temp . iteritems ( ) : if ( val not in result ) : result [ val ] = [ ] result [ val ] . append ( key ) return result
returns inverse of d .