Bird
0
0

You want to create a RunnableLambda that takes a string input and returns it reversed. Which code snippet correctly achieves this?

hard📝 Application Q8 of 15
LangChain - Chains and LCEL
You want to create a RunnableLambda that takes a string input and returns it reversed. Which code snippet correctly achieves this?
ARunnableLambda(lambda s: s[::-1])
BRunnableLambda(lambda s: s.upper())
CRunnableLambda(lambda s: s + s)
DRunnableLambda(lambda s: len(s))
Step-by-Step Solution
Solution:
  1. Step 1: Understand string reversal in Python

    Using slicing with [::-1] reverses a string.
  2. Step 2: Match lambda to reversal

    RunnableLambda(lambda s: s[::-1]) uses lambda s: s[::-1], which reverses the input string.
  3. Final Answer:

    RunnableLambda(lambda s: s[::-1]) -> Option A
  4. Quick Check:

    String reversal = s[::-1] in lambda [OK]
Quick Trick: Use s[::-1] to reverse strings in lambda [OK]
Common Mistakes:
  • Using upper() instead of reversal
  • Concatenating string instead of reversing
  • Returning length instead of reversed string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes