In article <3ed253bb-d6ec-4f47-af08-ad193e9c4...@h16g2000yqj.googlegroups.com>, odeits <ode...@gmail.com> wrote: >def count_consecutive(rows): > switch =3D 0 > count =3D 0 > for r in rows: > if r[-1] =3D=3D switch: > count +=3D 1 > else: > switch =3D not switch > if count !=3D 0: > yield count > count =3D 0 > if count !=3D 0: > yield count > >rows = [ ... ] > >for cnt in count_consecutive(rows): > print cnt
import itertools, operator for k, g in itertools.groupby(rows, operator.itemgetter(3): print len(list(g)) -- \S under construction -- http://mail.python.org/mailman/listinfo/python-list