File Organizer by Extension
Create a set of files with given extensions, then organize them into type-based subfolders (.pdf -> PDFs/, .jpg/.png -> Images/, .docx -> Documents/), matching the notes' own organizer.
Approach: create one file per given extension, then move each into the correct subfolder (creating it if needed), and finally report which files ended up in each subfolder.
Input: First line: the number of files n. Next n lines: one extension each (e.g. .pdf).
Output: One line: a list of (subfolder_name, [files]) tuples, sorted by subfolder name.
3 .pdf .jpg .docx
[('Documents', ['file2.docx']), ('Images', ['file1.jpg']), ('PDFs', ['file0.pdf'])]- 1 <= n <= 20
- Each extension is one of .pdf, .jpg, .png, .docx.
Hint 1
os.path.splitext(filename)[1].lower() gives the file's extension, used to look up its target subfolder in file_types.
Hint 2
os.makedirs(target, exist_ok=True) creates the destination subfolder if it doesn't exist yet.
Hint 3
shutil.move(src, dst) actually moves the file into its subfolder.
After creating one file per given extension, looping over os.listdir(folder) and looking up each file's extension in filetypes gives the correct destination subfolder name; os.makedirs(..., existok=True) creates it on first use, and shutil.move() relocates the file into it — exactly the notes' own organizer logic. Reporting the final subfolder contents (sorted, for predictable output) confirms everything landed in the right place.