From 8de6168ae47c1ca6502d75178b8032ea5cdb0b04 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Thu, 11 Oct 2012 11:44:14 +0200 Subject: [PATCH] Use defaultdict to generate the mapping --- find_reduced.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/find_reduced.py b/find_reduced.py index b504859..723a9fd 100755 --- a/find_reduced.py +++ b/find_reduced.py @@ -8,6 +8,7 @@ if len(sys.argv) != 2: import os from os import path +from collections import defaultdict from subprocess import Popen, PIPE from functools import cmp_to_key from datetime import datetime @@ -44,19 +45,13 @@ def flatten(l): if l: yield l.pop(0) # read mapping between Gentoo and Debian packages -deb2gen = dict() -gen2deb = dict() +deb2gen = defaultdict(list) +gen2deb = defaultdict(list) with open("./deb2gen_mapping.list") as f: for line in f: d, g = line.strip().split('\t') - if deb2gen.get(d): - deb2gen[d].append(g) - else: - deb2gen[d] = [g] - if gen2deb.get(g): - gen2deb[g].append(d) - else: - gen2deb[g] = [d] + deb2gen[d].append(g) + gen2deb[g].append(d) with open("./deb_source_pkgs.list") as f: debian_names = [p[4:].strip() for p in f]