I need to delete an item in a lists of list, based on the value in the inner list.
Example data:
persons = [ ['p1', 12, 45], ['p2', 10, 88] ['p3', 39, 66], ['p4', 34, 88], ['p5', 20, 16]]
I need to delete an item that has a value of 88, L1[x][3] == 88.
This is my code:
for i in range(len(persons)):
if persons[i][2] > longivity:
del persons[i]
I have used del L1(i), L1.remove[I] and a few others. I tried to use list comprehension, but I could get it to work correctly. I have tried so many variations, I'm quite lost. I tried several This is what I'm getting:
Traceback (most recent call last):ulation: 2 Murders: 0 Food supply: 104.0
File "/Users/bigd/Documents/Python/Projects/Simulators/first_sim.py", line 172, in <module>
year, longivity, infantMortality, food, persons, world, work_age, murders = runYear(
File "/Users/bigd/Documents/Python/Projects/Simulators/first_sim.py", line 144, in runYear
persons, murders = deadpool(longivity, year, murders, persons)
File "/Users/bigd/Documents/Python/Projects/Simulators/first_sim.py", line 109, in deadpool
if persons[i][2] > longivity:
IndexError: list index out of range