Why does one assignment both add an entry and silently overwrite one — and why is 'B' in grades False when B is sitting right there?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Here is a small price list:
prices = {'apple': 3, 'banana': 2, 'cherry': 7}
Two things have changed at the market: a date is now sold, at a price of 5, and a banana now costs 4 instead of 2. Apply both changes to prices itself — one statement each, using the same square-bracket assignment both times.
Assignment that adds or silently overwrites
Write grades['Grace'] = 'A' for the absent key and grades['Grace'] = 'C' for the present one, recording that the second replaces the old value with no check and no loop.
del and in-place mutation
Write del(grades['Ana']) to remove that key and its value, and state that adding, changing and deleting all alter the original dictionary rather than returning a copy.
in looks only at the keys
Record that 'John' in grades is True while 'Daniel' in grades and 'B' in grades are both False, then write find_in_L with its early return True and its outer return False.
Dictionaries as unordered collections
State that a dictionary is not an ordered sequence, note that Python 3.7 onward hands entries back in insertion order, and record which assumption robust code makes.