Dec-27-2022, 09:17 AM
(Dec-26-2022, 05:22 PM)deanhystad Wrote: Neither update() or a dictionary comprehension are the right tools for this problem.
update() will not work because you are not always adding keys to the dictionary, sometimes you want to modify existing dictionary values.
Indeed, .... Neither update() or a dictionary comprehension are the right tools for this problem.
Here is the solution that works ...
list1 = [dir1, dir2, dir3, dir4, dir5] files = {} for folder in list1: for f in os.listdir(folder): if f in files: files[f] = files[f] + [folder] else: files[f] = [folder] for k, v in files.items(): if len(v) > 1: print(f'{k:<60}{len(v):<3}{v}')