【发布时间】:2018-09-30 15:48:44
【问题描述】:
所以我在任何地方都找不到任何提及。也许我只是在寻找错误的东西,或者答案是如此明显,以至于我只是以某种方式错过了它。我开始使用二维数组,但找不到任何关于从列表中完全删除列表元素的方法。
基本上,我想从表中删除一行,这是我正在使用的代码;
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[highestEmployee]? -
完美运行!谢谢!