import sys indata = open(argv[1], "r") file1 = indata.readlines() indata = open(argv[2], "r") file2 = indata.readlines() all1 = 0 all2 = 0 for i in file1: t = i.split() all1 = all1 + int(t[1]) for k in file2: t = k.split() all2 = all2 + int(t[1]) s = [] for i in file1: t = i.split() proc1 = (float(t[1])/all1) * 100 proc1 = round(proc1, 4) p = t[0] + " " + str(proc1) s.append(p) for k in file2: t = k.split() proc2 = (float(t[1])/all2) * 100 proc2 = round(proc2, 4) for d in s: f = d.split() if str(f[0]) == str(t[0]): w = float(f[1]) - proc2 out = open(argv[3], "a") out.write("