def next_name(container, key):
    """
    Given a container object and some key prefix, yield the next key with the
    given prefix that is not contained into container.
    """
    if key not in container:
        return key
    for i in range(1, 1000):
        test = f"{key}_{i}"
        if test not in container:
            return test
    raise ValueError(f"could not find a valid name with the {key} prefix")