Page 4 of 11 Problem 3 Write the recursive function get _files list, which takes
ID: 3904232 • Letter: P
Question
Page 4 of 11 Problem 3 Write the recursive function get _files list, which takes a valid Path object representing directory/folder on a computer. path to some The function should return a list of Path objects for all paths that are files (and not folders). The given path is guaranteed to exist, so you do not need to validate it in your solution. You are required to use the pathlib library appropriately in your solution- some potentially useful information is below. Assume Path is imported from pathlib. Path.is_dir(self) Path.iterdir(self) Returns if a Path is a directory Allows iteration through subdirectories of a Path The Path constructor takes in a string representing a path. def get_files_list (path: Path) [Path]:Explanation / Answer
from pathlib import Path def get_files_list(path: Path) -> [Path]: result = [] if path.is_dir(): for child in path.iterdir(): result += get_files_list(child) else: result += [path] return result
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.