删除特定索引中的元素后如何加入数组的其余部分?
How do I join the rest of the array after having removed an element in a specific index?
删除特定索引中的元素后如何加入数组的其余部分?
我希望“漏洞”None 消失。
构造函数:
def __init__(self, capacity=8):
self.__data = [None] * capacity
self.__front = 0
self.__size = 0
有问题的功能:
def abandon_queue(self, index):
if self.is_empty():
raise ValueError('A fila está vazia! Não pode remover nenhum cliente')
while int(index) > 8 or int(index) < 0:
raise ValueError("Está fora da capacidade da fila")
while 0 <= int(index) <= 8:
remove = self.__data[int(index)]
self.__data[int(index)] = None
self.__front = (self.__front + 1) % len(self.__data)
self.__size -= 1
return remove
而不是 self.__data[int(index)] = None
,它将那个位置的项目设置为 None
,使用 self.__data.del(int(index))
,它删除项目并自动减少列表长度
删除特定索引中的元素后如何加入数组的其余部分? 我希望“漏洞”None 消失。 构造函数:
def __init__(self, capacity=8):
self.__data = [None] * capacity
self.__front = 0
self.__size = 0
有问题的功能:
def abandon_queue(self, index):
if self.is_empty():
raise ValueError('A fila está vazia! Não pode remover nenhum cliente')
while int(index) > 8 or int(index) < 0:
raise ValueError("Está fora da capacidade da fila")
while 0 <= int(index) <= 8:
remove = self.__data[int(index)]
self.__data[int(index)] = None
self.__front = (self.__front + 1) % len(self.__data)
self.__size -= 1
return remove
而不是 self.__data[int(index)] = None
,它将那个位置的项目设置为 None
,使用 self.__data.del(int(index))
,它删除项目并自动减少列表长度