Dict comprehension with two for
loops to the rescue:
letter_score = {letter: score for score, letters in scrabble_scores
for letter in letters.split()}
E.g. for every letter in the string (separated by whitespace), produce a key and value pair in the output dictionary; the key is the letter, the value the score.
Demo:
>>> scrabble_scores = [(1, "E A O I N R T L S U"), (2, "D G"), (3, "B C M P"),
... (4, "F H V W Y"), (5, "K"), (8, "J X"), (10, "Q Z")]
>>> letter_score = {letter: score for score, letters in scrabble_scores
... for letter in letters.split()}
>>> letter_score
{'A': 1, 'C': 3, 'B': 3, 'E': 1, 'D': 2, 'G': 2, 'F': 4, 'I': 1, 'H': 4, 'K': 5, 'J': 8, 'M': 3, 'L': 1, 'O': 1, 'N': 1, 'Q': 10, 'P': 3, 'S': 1, 'R': 1, 'U': 1, 'T': 1, 'W': 4, 'V': 4, 'Y': 4, 'X': 8, 'Z': 10}
>>> letter_score['Q']
10
Bonus word score calculator:
>>> word = 'QUICK'
>>> sum(letter_score[c] for c in word)
20
where word
is a uppercase string containing only (scrabble) letters, ignoring double- and triple-letter scoring.