Python: os.listdir alternative/certain extensions
glob
is good at this:
import glob
for f in glob.glob("*.f"):
print(f)
Don't ask what?
[s for s in os.listdir() if s.endswith('.f')]
If you want to check a list of extensions, you could make the obvious generalization,
[s for s in os.listdir() if s.endswith('.f') or s.endswith('.c') or s.endswith('.z')]
or this other way is a little shorter to write:
[s for s in os.listdir() if s.rpartition('.')[2] in ('f','c','z')]