Given a base path and a list with extensions the task is to list all files:
Two of my solutions are:
from glob import glob
from os import path
EXTENSIONS = ['*.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 reduce
Have you got any other ideas?
sum((glob(path.join(DOC_PATH, ext)) for ext in EXTENSIONS), [])
. – Josay yesterday