Bird
0
0

What will the following code print?

medium📝 Predict Output Q5 of 15
NLP - Word Embeddings
What will the following code print?
embedding = {'dog': [0.2, 0.3], 'cat': [0.1, 0.4]}
print(embedding.get('bird', [0.0, 0.0]))
ANone
B[0.0, 0.0]
CKeyError
D[0.2, 0.3]
Step-by-Step Solution
Solution:
  1. Step 1: Understand dictionary get() method

    get() returns value if key exists, else returns default provided.
  2. Step 2: Check if 'bird' key exists

    'bird' is not in embedding, so default [0.0, 0.0] is returned.
  3. Final Answer:

    [0.0, 0.0] -> Option B
  4. Quick Check:

    dict.get missing key = default value [OK]
Quick Trick: dict.get returns default if key missing [OK]
Common Mistakes:
MISTAKES
  • Expecting KeyError instead of default
  • Confusing get() with direct indexing
  • Assuming None is returned by default

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes