PY-10

Pair Values without Losing Alignment

  • Easy–Medium
  • Sequences and Alignment
  • Python

Task

Write pair_aligned(left, right, left_ids, right_ids). The four lists are aligned when they all have the same length and the ID at every position in left_ids equals the ID at that position in right_ids.

Return a two-item tuple:

(pairs, status)

Apply these rules in order:

  • If any of the four lists have different lengths, return ([], "unequal lengths").
  • Otherwise, if the IDs first differ at index i, return ([], "id mismatch at i"), with the actual index in the status string.
  • Otherwise, return a list of (left_value, right_value) pairs and the status "ok". Pair values at the same position; do not reorder them.

The input lists must not be changed. If the lengths differ, the length status has priority and no ID mismatch is reported.

Example

Your implementation

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

Each argument is a list. The value lists and ID lists are intended to describe the same positions. Return exactly (pairs, status), where pairs is a list and status is one of the strings defined above. Do not mutate any input, print a result, or ask for input.