所以我在任何地方都找不到任何关于这件事的报道。也许我只是在找错误的东西,或者答案太明显了,我只是不知怎的错过了。我开始使用二维数组,但是我找不到任何关于从列表中完全删除列表元素的方法的介绍。在
基本上,我想从表中删除一行,这是我正在处理的代码
employeeTable = [[2, 4, 3, 4, 5, 8, 8], [7, 3, 4, 3, 3, 4, 4], [3, 3, 4, 3, 3, 2, 2],
[9, 3, 4, 7, 3, 4, 1], [3, 5, 4, 3, 6, 3, 8], [3, 4, 4, 6, 3, 4, 4],
[3, 7, 4, 8, 3, 8, 4], [6, 3, 5, 9, 2, 7, 9]]
highestValue = 0
highestEmployee = 0
while employeeTable:
for i in range(len(employeeTable))
if sum(employeeTable[i]) > highestValue:
highestValue = sum(employeeTable[i])
highestEmployee = i
print("Employee " + highestEmployee + " has " + highestValue + " hours this week.")
在每个for循环完成后,我想从列表中删除8行中的一行,然后再次循环。我知道我可以从列表中弹出最上面的一行,但我更想知道是否有方法可以删除特定的行。在
正如斯蒂芬·劳赫提到的,你可以使用
del employeeTable[<row to delete>]
如果你想删除一行中的一个元素
del employeeTable[<row of element>][<position of element in row>]
相关问题 更多 >
编程相关推荐