I need some help with a project in Py 3. At the end of dictionary chapter is scrabble project. I have question regarding the last Task on it : “Make your defined dictionary that has upper case alphabets, handle lower case as well”
I can easily populate a new dictionary with lower case alphabets from the older dictionary, but is there a way that i can implement in dictionary comprehension where I could check my given alphabet to both upper and lower case using just one dictionary.
i mean i want to avoid generating another dictionary , just to cater to lower case scenario.
When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!
If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!
Hi, @rdb20 – Well, one way would be to make each key a tuple (“A”, “a”), (“B”, “b”), etc., but then you would need to modify score_word(), to poll the keys for the presence of the character: if letter in key:, etc.
@mtf’s solution is obviously the most straightforward approach.
I was under the impression that the problem was focused on modifying the dictionary. If that’s what you are trying to do, and you’re using tuples you can check like this:
def score_word(word):
point_total = 0
for letter in word:
for key in letter_to_points:
if letter in key: # Just use "in"; no need to check tuple items separately
point_total += letter_to_points[key]
return point_total