def batches(items, number):
 (div, mod) = divmod(len(items), number)
 if (div > 1):
  if mod:
   div += 1
  return batch_size(items, div)
 elif (not div):
  return ([[item] for item in items] + ([[]] * (number - mod)))
 elif ((div == 1) and (not mod)):
  return [[item] for item in items]
 else:
  return ([items[(i * 2):((i * 2) + 2)] for i in xrange(0, mod)] + [[item] for item in items[(mod * 2):]])

def batches ( items , number ) : ( div , mod ) = divmod ( len ( items ) , number ) if ( div > 1 ) : if mod : div += 1 return batch_size ( items , div ) elif ( not div ) : return ( [ [ item ] for item in items ] + ( [ [ ] ] * ( number - mod ) ) ) elif ( ( div == 1 ) and ( not mod ) ) : return [ [ item ] for item in items ] else : return ( [ items [ ( i * 2 ) : ( ( i * 2 ) + 2 ) ] for i in xrange ( 0 , mod ) ] + [ [ item ] for item in items [ ( mod * 2 ) : ] ] )
retrieves items in the given number of batches .