class Stats(object):

    def __init__(self):
        self.count = 0
self.subdirs = {}
counts = Stats()
for p in paths:
    parts = p.split('/')
branch = counts
for part in parts[1:]:
    branch = branch.subdirs.setdefault(part, Stats())
branch.count += 1
Python: рекурсивно создать словарь из путей