Pset 5, problem 1. Anybody know how to use the dictionary? Each letter from a to z were given a value, how to use the value to calculate the score?
Link please? I'm not following the course, but I'll be able to help. :)
the value of any letter is called by SCRABBLE_LETTER_VALUES [l] where "l" is the letter.
Ok. Dictionary is a structure that maps keys to values. Each key can have only one value associated with it (that value can be a list or some other structure though). In Python, if 'd' is a dictionary, then expression 'd[k]' yields a value associated with key 'k' if that key is present in 'd' - otherwise an exception is thrown. Symmetrically, an expression 'd[k] = v' assigns value 'v' to the key 'k'. In that exercise you're given a pre-populated dictionary that has all the letters as keys, and each of them is associated with a score. Is it clear now?
Join our real-time social learning platform and learn together with your friends!