python - List index out of range error -


so getting list index out of range error in python again, , can't figure out what's wrong.

#!/usr/bin/env python # -*- coding: utf-8 -*-  f1 = open("membrane_go.txt","r") new_list1 = f1.readlines() new_list2 = new_list1 in range(len(new_list1)):     if "reactome" in new_list1[i]:         new_list2.pop(i) print new_list2   f1.close() 

i made sure duplicated list being modified primary list iterated over, can't problem.

appreciate :)

you duplicated reference list. if want make separate copy of list, use slices: list2 = list1[:] or deepcopy module.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -