w = {} with open('t.txt') as trans_file: for l in trans_file: f,t,a = l.split(',') w[f] = w.get(f, 0) - int(a) w[t] = w.get(t, 0) + int(a) x = len([x for x in w if w[x] > 10]) print(x)