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
Post a Comment