A camera saves files in nested folders like /DCIM/2025_06_01/IMG_0001.jpg. Model its memory card.
Implement CameraCard() with:
save(path): store a file, creating missing parent folders. Saving an existing file changes nothing.find(folder, ext) -> list[str]: sorted full paths of every file at any depth underfolderwhose name ends with"." + ext(case-sensitive;"jpg"alone doesn't match). A missing folder, or a file path, gives[].remove(path) -> int: delete the file or whole folder atpathand return how many files went. Its parent stays, even if empty. Nothing there: return0.remove("/")empties the card.
card = CameraCard()
card.save("/DCIM/day1/a.jpg")
card.save("/DCIM/day1/a.xmp")
card.save("/DCIM/day2/b.jpg")
card.save("/c.jpg")
card.find("/", "jpg") # ["/DCIM/day1/a.jpg", "/DCIM/day2/b.jpg", "/c.jpg"]
card.find("/DCIM/day1", "xmp") # ["/DCIM/day1/a.xmp"]
card.remove("/DCIM/day1") # 2
card.find("/DCIM", "jpg") # ["/DCIM/day2/b.jpg"]
card.remove("/DCIM/day1") # 0 (already gone)
Paths are absolute with no trailing slash (except "/"); files and folders never collide.
Show hint
nested dicts (name → dict for a folder, None for a file). find is a DFS carrying the path so far; remove walks to the parent and deletes one key, counting files in what it removes.