I'm new to Python, and i'm struggling to understand the output of this simple program:
list = os.listdir(os.getcwd())
print(list)
print()
for element in list:
print(element)
if 'txt' not in element: list.remove(element)
Which gives me this output :
['examples_list.txt', 'generate_patterns.py', 'lehoczky_example_3.txt', 'patterns', 'test.py', 'test2.py']
examples_list.txt
generate_patterns.py
patterns
test2.py
why are certain elements (such as 'lehoczky_example_3.txt'), ignored by the "for" loop?