Bird
0
0

Given the following code snippet, what will be the output?

medium📝 Analysis Q4 of 15
LLD - Design — Splitwise (Expense Sharing)
Given the following code snippet, what will be the output?
transactions = [
  {'id': 't1', 'amount': 100},
  {'id': 't2', 'amount': 200}
]
print(len(transactions))
A2
B1
C0
DError
Step-by-Step Solution
Solution:
  1. Step 1: Count the number of elements in the list

    The list has two dictionaries representing two transactions.
  2. Step 2: Understand len() function behavior

    len() returns the number of items in the list, which is 2.
  3. Final Answer:

    2 -> Option A
  4. Quick Check:

    len() of list with 2 items = 2 [OK]
Quick Trick: len() returns count of list elements [OK]
Common Mistakes:
  • Confusing len() with sum()
  • Expecting output as 1 or 0
  • Thinking it causes an error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes