pathlib — the file API AI should reach for first — step 8 of 9
Write a function list_text_files(folder) that returns a list of the
names (not full paths) of all .txt files directly inside folder,
in sorted order.
Use Path.glob("*.txt") to find them. Use .name to get just the
filename from each Path. Wrap the result in sorted(...).
The starter creates three files in /tmp/notes/. Calling the function
should produce:
['alpha.txt', 'beta.txt']
(The .md file is filtered out by the glob.)
Write a function list_text_files(folder) that returns a list of the
names (not full paths) of all .txt files directly inside folder,
in sorted order.
Use Path.glob("*.txt") to find them. Use .name to get just the
filename from each Path. Wrap the result in sorted(...).
The starter creates three files in /tmp/notes/. Calling the function
should produce:
['alpha.txt', 'beta.txt']
(The .md file is filtered out by the glob.)
this step needs the editor
on desktop today; in the app (coming soon). save your spot and we'll bring you back here when you're ready.