def to_dict(sequences, key_function=None):
 if (key_function is None):
  key_function = (lambda rec: rec.id)
 d = dict()
 for record in sequences:
  key = key_function(record)
  if (key in d):
   raise ValueError(("Duplicate key '%s'" % key))
  d[key] = record
 return d

def to_dict ( sequences , key_function = None ) : if ( key_function is None ) : key_function = ( lambda rec : rec . id ) d = dict ( ) for record in sequences : key = key_function ( record ) if ( key in d ) : raise ValueError ( ( "Duplicate key '%s'" % key ) ) d [ key ] = record return d
given something that closely resembles a dictionary .