I have a list of glob patterns. For each glob pattern, I get the matching file list, and I want to combine all the file lists with list comprehension to be one flattened list:
patterns = [
"some_pattern1",
"some_pattern2"
]
all_files = []
all_files.extend(glob.glob(pattern)) for pattern in patterns
However this gives me a syntax error, I can do the list merge with:
for pattern in patterns:
all_files.extend(glob.glob(pattern))
I think those two syntax are equivalent. Why the list comprehension doesn't work with extend?
For exmaple, consider some_pattern1
matches two files [1.txt, 2.txt]
; some_patter2
matches [3.txt, 4.txt]
, I'm looking for a way to combine the two lists to be: [1.txt, 2.txt, 3.txt, 4.txt]