all_of_them = [] current = 0 with open("1_1.in") as fh: for line in fh: line = line.strip() if not line: all_of_them.append(current) current = 0 continue current += float(line) all_of_them.sort(reverse=True) print(sum(all_of_them[:3]))