import random


def mutate_delete(individual: list):
    """Deletes a node from a tensor network"""
    tensor_net = individual[1]
    length = len(tensor_net.get_middle_nodes())

    if length == 0:  # nothing to delete
        # noinspection PyRedundantParentheses
        return (individual,)

    position = random.randint(0, length - 1)
    node_id = list(tensor_net.get_middle_nodes().keys())[position]
    tensor_net.delete_node(node_id=node_id)
    # noinspection PyRedundantParentheses
    return (individual,)