def generate_tuple_batches(qs, batch_len=<NUM_LIT:1>):
num_items, batch = <NUM_LIT:0>, []<EOL>for item in qs:<EOL><INDENT>if num_items >= batch_len:<EOL><INDENT>yield tuple(batch)<EOL>num_items = <NUM_LIT:0><EOL>batch = []<EOL><DEDENT>num_items += <NUM_LIT:1><EOL>batch += [item]<EOL><DEDENT>if num_items:<EOL><INDENT>yield tuple(batch)<EOL><DEDENT>
Iterate through a queryset in batches of length `batch_len`

    >>> [batch for batch in generate_tuple_batches(range(7), 3)]
    [(0, 1, 2), (3, 4, 5), (6,)]