def single_key(dict_):
    """dict must have exactly one key, return it.

    Raises ValueError if the dict has more than one key.
    """
    keys = list(dict_.keys())
    if len(keys) != 1:
        raise ValueError("dict hasn't exactly one key: %s" % repr(keys))
    return keys[0]
