text_files(folder) returning a sorted list of the file names (not full paths) in folder that end with .txt, case-insensitively (.TXT matches too). Use os.listdir.text_files('docs') # folder holds a.txt, b.PDF, c.TXT['a.txt', 'c.TXT']
Both .txt variants match; the PDF does not.
name.lower().endswith('.txt').
os.listdir gives names only, which is what we want.