Bird
0
0

You want to run three independent tasks taskX, taskY, and taskZ in parallel and combine their results into a single string separated by commas. Which code correctly does this?

hard📝 Application Q15 of 15
LangChain - Chains and LCEL
You want to run three independent tasks taskX, taskY, and taskZ in parallel and combine their results into a single string separated by commas. Which code correctly does this?
Aparallel = RunnableParallel(taskX, taskY, taskZ) results = parallel.invoke() combined = ','.join(results) print(combined)
Bparallel = RunnableParallel({"taskX": taskX, "taskY": taskY, "taskZ": taskZ}) results = parallel.invoke() combined = ','.join(results.values()) print(combined)
Cresults = [taskX(), taskY(), taskZ()] combined = ','.join(results) print(combined)
Dparallel = RunnableParallel([taskX, taskY, taskZ]) combined = parallel.invoke().join(',') print(combined)
Step-by-Step Solution
Solution:
  1. Step 1: Create RunnableParallel with dictionary of tasks

    parallel = RunnableParallel({"taskX": taskX, "taskY": taskY, "taskZ": taskZ}) results = parallel.invoke() combined = ','.join(results.values()) print(combined) correctly passes tasks as a dictionary to RunnableParallel.
  2. Step 2: Invoke and join results properly

    This calls invoke() to get dict results, then joins the values with commas correctly.
  3. Step 3: Check other options for errors

    parallel = RunnableParallel(taskX, taskY, taskZ) results = parallel.invoke() combined = ','.join(results) print(combined) passes tasks incorrectly as positional; C runs tasks sequentially; D uses invalid list and misuses join.
  4. Final Answer:

    Using RunnableParallel({"taskX": taskX, "taskY": taskY, "taskZ": taskZ}) and ','.join(results.values()) -> Option B
  5. Quick Check:

    Dict tasks + invoke + join values = correct [OK]
Quick Trick: Pass tasks as dict, invoke, then ','.join(results.values()) [OK]
Common Mistakes:
  • Passing tasks without dictionary syntax
  • Calling join() on the wrong object
  • Running tasks sequentially instead of parallel

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes