groups = itertools.groupby(allLines, lambda x: x[1])
for k, lines in groups:
    firstLine = next(iter(g))
print(firstLine[0], firstline[1], sum(int(x[2]) for x in lines))
Merging 2 very large text files, update each line, without using memory