79804954

Date: 2025-10-30 15:55:32
Score: 1.5
Natty:
Report link

Is this the best general-purpose solution?

def batch(iteration, batchSize):
    items = []
    for item in iteration:
        items.append(item)
        if len(items) == batchSize:
            yield items
            items = []
    if items:
        yield items

...
for rows in batch(query.results(), N):
    cluster.submit(rows)
Reasons:
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Self-answer (0.5):
  • Starts with a question (0.5): Is this the
  • High reputation (-1):
Posted by: Mikhail T.