Your names
dict looks like that:
{
'file1.txt': 30,
'file2.txt': 26,
'file3.txt': 19,
'file4.txt': 19
}
So you’d just have to start from that and follow with:
from collections import defaultdict
lines = defaultdict(int)
for val in names.values():
lines[val] += 1
for k, v in lines.items():
print("Files with {} lines: {}".format(k, v))
This will print something like:
Files with 19 lines: 2
Files with 26 lines: 1
Files with 30 lines: 1
0
solved Python script counting lines in multiple text files in one directory and producing simple report