#18Rebuild findings from gather resultsEasy

Rebuild findings from gather results

Background

asyncio.gather(*coros) returns results in the same order as the coroutines you passed. After launching one executor per sub-question, you zip the sub-question list back together with the results to rebuild the findings dict:

results = await asyncio.gather(*[self._react(sq) for sq in sub_questions])
findings = {sub_questions[i]: results[i] for i in range(len(sub_questions))}

Problem statement

Implement gather_findings(sub_questions, results) returning the {sub_question: result} dict.

Input

  • sub_questions — list of sub-question strings (the order launched).
  • results — list of results, aligned by index with sub_questions.

Output

Returns a dict mapping each sub-question to its result, in order.

Examples

Example 1

Input:  sub_questions = ["What benchmark?", "What training data?"],
        results = ["CodeContests", "filtered GitHub code"]
Output: {"What benchmark?": "CodeContests", "What training data?": "filtered GitHub code"}

Constraints

  • Pair sub_questions[i] with results[i].
  • Preserve order.

Notes

  • Order alignment is the whole reason gather is safe here: you never lose track of which answer belongs to which question.
Python
Loading...

▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.

  • Reference example: two aligned pairs
  • Sample: single pair
  • Reference: order preserved for three pairs