Bird
0
0

Identify the error in this code snippet that tries to update a transaction amount:

medium📝 Analysis Q6 of 15
LLD - Design — Splitwise (Expense Sharing)
Identify the error in this code snippet that tries to update a transaction amount:
transactions = [{'id': 't1', 'amount': 100}]
transactions['t1']['amount'] = 150
Atransactions is a list, not a dictionary, so key access by 't1' is invalid
BThe amount key is misspelled
CThe assignment operator is incorrect
DThe list is empty
Step-by-Step Solution
Solution:
  1. Step 1: Analyze data structure type

    transactions is a list, so it cannot be accessed by string keys like 't1'.
  2. Step 2: Understand correct access method

    To update, you must find the dictionary in the list with id 't1' and then update its amount.
  3. Final Answer:

    transactions is a list, not a dictionary, so key access by 't1' is invalid -> Option A
  4. Quick Check:

    List accessed by key = Error [OK]
Quick Trick: Lists use index, dicts use keys for access [OK]
Common Mistakes:
  • Accessing list with string key
  • Assuming amount key typo
  • Misusing assignment operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes