I wrote a program of python as below:
from os import listdir
def getfilename():
namelist=listdir(".")
print namelist
for name in namelist:
print name
if 'lp' in name:
namelist.remove(name)
return namelist
when I run it on the command line and print the return value, the result is :
['all_test1.list', 'all_test2.list', 'lp.py', 'lp.pyc', 'lp.test', 'straightrnd_test1.list', 'straightrnd_test2.list', 'straightrnd_train.list']
all_test1.list
all_test2.list
lp.py
lp.test
straightrnd_test2.list
straightrnd_train.list
['all_test1.list', 'all_test2.list', 'lp.pyc', 'straightrnd_test1.list', 'straightrnd_test2.list', 'straightrnd_train.list']
The file 'lp.pyc' lost in for loop, so the return value contains it, I wanna remove it from the list,what should I do? Why the element lost in for loop?