Python 包含文件夹路径转字典
作者:互联网
def dictizeString(string, value, dictionary):
while string.startswith('/'):
string = string[1:]
parts = string.split('/', 1)
if len(parts) > 1:
branch = dictionary.setdefault(parts[0], {})
#branch = dictionary.setdefault(parts[0], value)
#dictizeString(parts[1], branch)
dictizeString(parts[1], value, branch)
else:
if dictionary.has_key(parts[0]):
dictionary[parts[0]] += 1
else:
dictionary[parts[0]] = value
office = {}
for k, v in worker.items():
dictizeString(k, v, office)
print(office)
标签:dictizeString,string,dictionary,Python,parts,value,文件夹,branch,字典 来源: https://blog.csdn.net/u012206617/article/details/121362102