How can I get a flat result from a list comprehension instead of a nested list?
You can have nested iterations in a single list comprehension: [filename for path in dirs for filename in os.listdir(path)] which is equivalent (at least functionally) to: filenames = [] for path in dirs: for filename in os.listdir(path): filenames.append(filename)