Bird
0
0

An AI-generated itinerary code:

medium📝 Analysis Q7 of 15
AI for Everyone - AI for Personal Productivity
An AI-generated itinerary code:
itinerary = {'Day 1': ['Park', 'Lunch']}
What is wrong with this code if you want to add 'Museum' to Day 1 activities?
AYou should append 'Museum' to the list for 'Day 1'
BYou cannot add items to a list inside a dictionary
CYou must replace the entire list instead of appending
DYou need to create a new dictionary for 'Museum'
Step-by-Step Solution
Solution:
  1. Step 1: Understand list modification inside dictionary

    Lists inside dictionaries can be modified by appending items.
  2. Step 2: Identify correct way to add 'Museum'

    Appending 'Museum' to the list for 'Day 1' is correct.
  3. Final Answer:

    You should append 'Museum' to the list for 'Day 1' -> Option A
  4. Quick Check:

    Modify list inside dict by append [OK]
Quick Trick: Use list append to add activities inside dictionary values [OK]
Common Mistakes:
MISTAKES
  • Thinking you must replace the whole list
  • Believing lists inside dicts are immutable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AI for Everyone Quizzes