from itertools import groupby

ls = [(0,7), (1,7), (0,5), (1,5), (2,5), (0,9), (9,9)]

i = 0
def grp(kv):
    global i
    if kv[0] == 0:
        i += 1
    return i


for i,row in groupby(ls, grp):
    print list(row)

