def do_batch(value, linecount, fill_with=None):
 result = []
 tmp = []
 for item in value:
  if (len(tmp) == linecount):
   (yield tmp)
   tmp = []
  tmp.append(item)
 if tmp:
  if ((fill_with is not None) and (len(tmp) < linecount)):
   tmp += ([fill_with] * (linecount - len(tmp)))
  (yield tmp)

def do_batch ( value , linecount , fill_with = None ) : result = [ ] tmp = [ ] for item in value : if ( len ( tmp ) == linecount ) : ( yield tmp ) tmp = [ ] tmp . append ( item ) if tmp : if ( ( fill_with is not None ) and ( len ( tmp ) < linecount ) ) : tmp += ( [ fill_with ] * ( linecount - len ( tmp ) ) ) ( yield tmp )
a filter that batches items .