How can I iterate over files in a given directory?

Python 3.6 version of the above answer, using os – assuming that you have the directory path as a str object in a variable called directory_in_str: import os directory = os.fsencode(directory_in_str) for file in os.listdir(directory): filename = os.fsdecode(file) if filename.endswith(“.asm”) or filename.endswith(“.py”): # print(os.path.join(directory, filename)) continue else: continue Or recursively, using pathlib: from pathlib import … Read more

How to build a basic iterator?

Iterator objects in python conform to the iterator protocol, which basically means they provide two methods: __iter__() and __next__(). The __iter__ returns the iterator object and is implicitly called at the start of loops. The __next__() method returns the next value and is implicitly called at each loop increment. This method raises a StopIteration exception … Read more

Iterator invalidation rules for C++ containers

C++03 (Source: Iterator Invalidation Rules (C++03)) Insertion Sequence containers vector: all iterators and references before the point of insertion are unaffected, unless the new container size is greater than the previous capacity (in which case all iterators and references are invalidated) [23.2.4.3/1] deque: all iterators and references are invalidated, unless the inserted member is at … Read more