pathlib
Completed
Using pathlib.Path, create a folder data, write each input word to data/WORD.txt containing the word in upper case, then print the sorted file names in the folder and the content of the first one.
Input
One line of words.
Output
The file names, then one content line.
Example
Input
pear apple fig
Output
apple.txt fig.txt pear.txt APPLE
Editor
Python
Hints
Path / "name" joins paths.
write_text and read_text open and close the file for you.
Solution explanation
pathlib is the modern, object-oriented way to work with files and folders.
Show solution
from pathlib import Path
folder = Path("data")
folder.mkdir(exist_ok=True)
for word in input().split():
(folder / f"{word}.txt").write_text(word.upper())
names = sorted(p.name for p in folder.iterdir())
print(*names)
print((folder / names[0]).read_text())