def do_slice(value, slices, fill_with=None):
 seq = list(value)
 length = len(seq)
 items_per_slice = (length // slices)
 slices_with_extra = (length % slices)
 offset = 0
 for slice_number in range(slices):
  start = (offset + (slice_number * items_per_slice))
  if (slice_number < slices_with_extra):
   offset += 1
  end = (offset + ((slice_number + 1) * items_per_slice))
  tmp = seq[start:end]
  if ((fill_with is not None) and (slice_number >= slices_with_extra)):
   tmp.append(fill_with)
  (yield tmp)

def do_slice ( value , slices , fill_with = None ) : seq = list ( value ) length = len ( seq ) items_per_slice = ( length // slices ) slices_with_extra = ( length % slices ) offset = 0 for slice_number in range ( slices ) : start = ( offset + ( slice_number * items_per_slice ) ) if ( slice_number < slices_with_extra ) : offset += 1 end = ( offset + ( ( slice_number + 1 ) * items_per_slice ) ) tmp = seq [ start : end ] if ( ( fill_with is not None ) and ( slice_number >= slices_with_extra ) ) : tmp . append ( fill_with ) ( yield tmp )
slice an iterator and return a list of lists containing those items .