Python dict.update
Apply all supplied opening-hour overrides to a working schedule.
A simple example
dict.update
- Start with A = 1, B = 2
- Do this Merge B = 3 and C = 4
- Result A = 1, B = 3, C = 4
Syntax
hours.update(overrides)
Run these examples in Python
Save one example at a time as lesson.py. Use Python 3.9 or later.
python3 lesson.pyApply weekend opening hours
A library keeps standard opening hours for every day, then receives a short list of weekend changes. The scheduler applies those overrides while preserving weekdays that the weekend list never mentions.
hours = {"Mon": 9, "Sat": 9}
hours.update({"Sat": 10, "Sun": 11})
print(hours["Sat"])
10
Saturday's previous opening hour is replaced by ten.
Merge weekend opening hours
The branch receives an updated Saturday timetable. A later set of assignments is merged into the first. Which value does the overlapping key hold?
Merge a volunteer rota
The organizer imports a replacement Saturday volunteer. A later set of assignments is merged into the first. Which value does the overlapping key hold?
What to watch for
update changes the destination and returns None. Keep using the destination after the call.