Use collections.Counter instead of manually

This commit is contained in:
Ewoud Kohl van Wijngaarden 2012-10-12 13:00:38 +02:00 committed by josch
parent 8de6168ae4
commit d9a5257255

View file

@ -8,7 +8,7 @@ if len(sys.argv) != 2:
import os
from os import path
from collections import defaultdict
from collections import Counter, defaultdict
from subprocess import Popen, PIPE
from functools import cmp_to_key
from datetime import datetime
@ -208,12 +208,7 @@ for d in debian_names:
sys.stderr.write("%s\n%s\n"%(list(set(missing_deb_mappings)),list(set(missing_gen_mappings))))
drop_freq = dict()
for p in all_droppable:
if drop_freq.get(p):
drop_freq[p] += 1
else:
drop_freq[p] = 1
drop_freq = Counter(all_droppable)
for k in sorted(drop_freq.keys(), key=drop_freq.__getitem__, reverse=True)[:20]:
sys.stderr.write("%s: %s\n"%(k, drop_freq[k]))
for package, freq in drop_freq.most_common(20):
sys.stderr.write("%s: %s\n"%(package, freq))