PY-37

Group Aligned Fields into Batches

  • Medium
  • Batching and Alignment
  • Python

Task

Write batch_aligned_fields(ids, values, labels, size). The first three arguments are equally long lists describing the same rows: item i in each list belongs together. size is a positive integer.

Return a list of dictionaries. Each dictionary must have exactly the keys ids, values, and labels; its values are lists containing one consecutive batch from the corresponding input. Keep rows aligned, preserve source order, and keep a shorter final batch when the length is not divisible by size. Return an empty list for three empty inputs. Do not modify any input, and make every returned batch list a new list.

Example

The equal-length and positive-size conditions are guaranteed, so no error status is needed.

Your implementation

Edit solution.py and keep this function name and signature:

Use the same slice boundaries for all three fields. Return dictionaries with no extra keys, and do not reuse an input list as a batch list.