Bird
0
0

What will be the output of this code simulating a sequence model?

medium📝 Predict Output Q5 of 15
NLP - Sequence Models for NLP
What will be the output of this code simulating a sequence model?
sentence = ['hello', 'world']
state = ''
for word in sentence:
    state += word[0]
print(state)
Ahw
Bhello
Cworld
Dhl
Step-by-Step Solution
Solution:
  1. Step 1: Understand the loop operation

    For each word, the first letter (word[0]) is added to state.
  2. Step 2: Apply to each word

    'hello' first letter is 'h', 'world' first letter is 'w', so state becomes 'hw'.
  3. Final Answer:

    hw -> Option A
  4. Quick Check:

    First letters concatenated = A [OK]
Quick Trick: Concatenate first letters to track order [OK]
Common Mistakes:
MISTAKES
  • Confusing full word with first letter
  • Mixing order of letters
  • Printing variable before loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes