I would like to iterate over the elements of a list, and delete the wrong ones. First, lets check all elements:
tikzFiles=['keepme.tikz','inputs.tex','bla1.bat','bla2.tex','bla3.py']
for sFile in tikzFiles:
print(sFile)
print(sFile.endswith('.tikz'))
This leads to the expected result:
keepme.tikz
True
inputs.tex
False
bla1.bat
False
bla2.tex
False
bla3.py
False
Two more lines, however,
for sFile in tikzFiles:
print(sFile)
print(sFile.endswith('.tikz'))
if not sFile.endswith('.tikz'):
tikzFiles.remove(sFile)
let the for-loop ignore the elements 'bla1.bat' and 'bla3.py':
keepme.tikz
True
inputs.tex
False
bla2.tex
False