from pathlib import Path path_bills = "factures-2019-2023" #fonction qui classe les PDFs par editeur def metrics_editors(path): dic_stats = {} files = Path('./%s/' %path).glob('*') for file in files: code_editor=str(file).split("_")[1] if code_editor not in dic_stats: dic_stats[code_editor]=1 else : dic_stats[code_editor]+=1 return dict(sorted(dic_stats.items(), key=lambda item:item[1])) print(metrics_editors(path=path_bills))