If Python hashes a key to decide where its value is stored, what happens to that value when the key itself changes?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
Memory has 16 slots, numbered 0 through 15. The hash function scores each letter by its place in the alphabet (A is 1, B is 2, … Z is 26), adds those scores up across the whole name, and reduces the total to a legal slot number.
Work out which slot the name in name hashes to and assign it to slot. Write it as a computation over the letters, not as a number you worked out on paper — the same code should work for any uppercase name and any num_slots.
Useful pieces: ord(ch) gives a character's code point (ord('A') is 65), and % is Python's remainder operator.
Hashing a key to a storage slot
Work the 16-slot example: sum the letter numbers of 'Ana', 'Eric' and 'John' mod 16 to reach slots 0, 3 and 15, then re-run it on Kate renamed Cate for 5 and 13.
A dictionary whose values are dictionaries
Write my_d with 'Ana', 'Fredo' and 'Eric' mapped to inner 'mq' and 'ps' dictionaries, then read my_d['Eric']['mq'][0] left to right down to the score 3.
Concatenation, not append, for gathering scores
Record that data[stud][what] is a list, and set all_data + data[stud][what] giving ['a', 'b', 'c', 10, 10] against append giving ['a', 'b', 'c', [10, 10]].