def invert_unique(d, check=True):
 if check:
  assert (len(set(d.values())) == len(d)), 'Values were not unique!'
 return {v: k for (k, v) in iteritems(d)}

def invert_unique ( d , check = True ) : if check : assert ( len ( set ( d . values ( ) ) ) == len ( d ) ) , 'Values were not unique!' return { v : k for ( k , v ) in iteritems ( d ) }
invert a dictionary with unique values into a dictionary with pairs flipped .