def invert(d):
 out = {}
 for (k, v) in iteritems(d):
  try:
   out[v].add(k)
  except KeyError:
   out[v] = {k}
 return out

def invert ( d ) : out = { } for ( k , v ) in iteritems ( d ) : try : out [ v ] . add ( k ) except KeyError : out [ v ] = { k } return out
invert an image .