'How do I rearrange node's number after removing node in singly linked list in python?

    index = 0
    current = self._head
    prevv = self._head
    temp = self._head
    while current is not None:
        if index == i:
            temp = current.next
            self._num_nodes -=1
            break
        prevv = current
        current = current.next
        index += 1
        prevv.next = temp
        return prevv

I already done when number of node is empty, 1, and I'm removing data in list with given index.(not first index or last index) And I got error that 'list's instance is not equal to number of data object' How can I solve this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source