It is easy to make itertools.groupby
work for you to get an iterable of iterables, without creating any temporary lists:
groupby(iterable, (lambda x,y: (lambda z: x.next()/y))(count(),100))
Don't get put off by the nested lambdas, outer lambda runs just once to put count()
generator and the constant 100
into the scope of the inner lambda.
I use this to send chunks of rows to mysql.
for k,v in groupby(bigdata, (lambda x,y: (lambda z: x.next()/y))(count(),100))):
cursor.executemany(sql, v)