Depending on your application the proposed solution can be inefficient as it has to loop over all files in the directory multiples times, (one for each extension/pattern).
In your example you are only matching the extension in one folder, a simple solution could be:
from pathlib import Path
folder = Path("/path/to/dir")
extensions = {".jl", ".jsonlines"}
files = [file for file in folder.iterdir() if file.suffix in extensions]
Which can be turned in a function if you use it a lot.
However, if you want to be able to match glob patterns rather than extensions, you should use the match()
method:
from pathlib import Path
folder = Path("/path/to/dir")
patterns = ("*.jl", "*.jsonlines")
files = [f for f in folder.iterdir() if any(f.match(p) for p in patterns)]
This last one is both convenient and efficient. You can improve efficiency by placing most common patterns at the beginning of the patterns list as any
is a short-circuit operator.