def generate_new_id(collection, basename):
    """Generate unique id for a node."""
    node_id = basename
    i = 1
    while node_id in collection:
        node_id = "{}_{}".format(basename, i)
        i += 1
    return node_id