# Scrabble Project On Computer Science Course

Hi guys, first time posting here, I had a question about the scrabble project on the computer science course. Once I run my code the outcome is “`{'player1': 29, 'wordNerd': 32, 'Lexi Con': 31, 'Prof Reader': 31}`” but when I watched along with the Youtube walkthrough I noticed that
the developers result showed the points decending from highest to lowest (from ‘wordNerd’ to ‘player1’). Any chance someone knows how they were able to get the outcome like that? any help will be greatly appreaciated! (the whole code I had is below)

``````letters = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
points = [1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 4, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10]

letter_to_points = {key: value for key, value in zip(letters, points)}

letter_to_points[" "] = 0
#print(letter_to_points)

def score_word(word):
point_total = 0
for letter in word:
point_total += letter_to_points.get(letter, 0)
return point_total

brownie_points = score_word("BROWNIE")
#print(brownie_points)

player_to_words = {
"player1": ["BLUE", "TENNIS", "EXIT"],
"wordNerd": ["EARTH", "EYES", "MACHINE"],
"Lexi Con": ["ERASER", "BELLY", "HUSKY"],
}

player_to_points = {}
for player, words in player_to_words.items():
player_points = 0
for word in words:
player_points += score_word(word)
player_to_points[player] = player_points
print(player_to_points)
``````

Hi,

What you’re looking for here is a way of sorting a Dictionary in descending order.
This article goes through some of the common methods of doing this: Sort Dictionary by Value Python Descending - GeeksforGeeks.

The simplest of which is probably using a Lambda function:

``````output = dict(input_dict.items(), key=lambda item: item[1], reverse=True))
``````

(Where `input_dict` would be your `player_to_points`).

However, if a value is changed, the order may break the sorted requirement, so the list would have to be sorted again. This can become inefficient if a large number of changes are made.

In reality, if the ordering of the output is not essential, it would be best to avoid unnecessary computation.

Hope that helps!

1 Like