Question
8. Update Entries in a Dictionary Dictionary entries can be modified or updated. If our person Lisa has a birthday, then her age needs to
8. Update Entries in a Dictionary
Dictionary entries can be modified or updated. If our person Lisa has a birthday, then her age needs to be updated. To update her age simply use the 'age' key and assign a new value:
person['age']=30
The resulting dictionary could be viewed as:
{'name':'Lisa', 'age':30, 'school':'SNHU'}
RUN THE CODE TO THE LEFT
Grocery_List
1 Create dictionary with a grocery list. Assign the dictionary to the variable grocery_list
2 Print out the contents of grocery_list, one item at a time, in the order: name, cost, quantity.
3 Update the quantity to 3
4 Print out the contents of grocery_list, one item at a time, in the order: name, cost, quantity, after the quantity update.
Notes included:
# Create dictionary with a grocery list.Assign the dictionary to the variable grocery_list
# Print out the contents of grocery_list
# Update the quantity to 3
# Print out the contents of grocery_list after updating the quantity
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started