with open(filename) as file:
    for i, line in enumerate(file):
        x, y, _ = line.split(parse, 2)
row_col = point_grid_id(float(x), float(y), minx, maxy, size)
try:
    n, selected_i = selection[row_col]
except KeyError:
    selection[row_col] = 1, i
else:
    n += 1
if random() < 1.0 / n:
    pass
Most memory efficient way to read chunk in a buffer in Python