vendredi 26 octobre 2018

Error while running for loop: index out of range

I have a list called 'rows' having count 160093 (all sublists). Count of each sublist is 5. I run the following code :

for i in range(1,len(rows)):
    if int(rows[i][1]) < 2010: 
        del rows[i]
    if int(rows[i][1]) > 2015:
        del rows[i]

So what this code does is checks the second element of sublist (say its 1976, stored as string) and if value is < 2010 or > 2015, deletes that row.

However, i keep getting the below error:

IndexError: list index out of range

Can someone please help ?

Aucun commentaire:

Enregistrer un commentaire