Python pathlib iterdir subdirectories
Python pathlib.Path.iterdir only iterates over a single directory level. It does not recurse directories.
A common task is to iterate over each subdirectory of a top-level directory non-recursively. For example, given directory structure:
/tmp/a/b /tmp/z /tmp/y/1/2
The Python iterdir example would return (in unspecified order):
/tmp/a /tmp/z /tmp/y
Notice in the C++ and Python examples, iterators are used that emit one element at a time rather than building up an entire list at once. Since directory operations are often unordered, there is no advantage to retrieving every directory name in a greedy operation rather than the lazy generators shown, particularly if networked file systems are being used.