Given a base path and a list with extensions the task is to list all files:Two of my solutions are:from glob import globfrom os import pathEXTENSIONS = ['*.zip', '*.jar', '*.pdf']DOC_PATH = '/path/to/files'# Solution1:files = []         for ext in EXTENSIONS:    files.extend(glob(path.join(DOC_PATH, ext)))# works but looks very clumsy# Solution2:files = reduce(lambda x,y: x+y,               [glob(path.join(DOC_PATH, ext)) for ext in EXTENSIONS])# Also functional but looks like a misuse of reduceHave you got any other ideas?
Pythonic way for double iteration (list all files with extensions)
python
If you only need to iterate over them (once) and not an actual list, you could use itertools.chain and glob.iglob:files = chain(*(iglob(path.join(DOC_PATH, ext)) for ext in EXTENSIONS))If you do need an actual list, you can further call list(files), of course.