Question: Question 1 . 2 Write a function called count _ file _ types that takes as input a folder ( a Path object ) ,

Question 1.2
Write a function called count_file_types that takes as input a folder (a Path object), and returns a dictionary with the number of files of each type in the folder. That is, if the folder contains 2 txt files and 3 pdf files, then the returned dictionary will be
{'.txt':2,'.pdf':3}
Hints:
Use for p in folder.iterdir() to iterate through the items in the folder.
Use is_file() to check that an item is a file (and not a subdirectory).
Get a file's extension with p.suffix.
Check whether a string a is a key in a dictionary A with a in A.keys().

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!