Hi, I am doing this exercise. I have a dictionary with names of players as the keys, and lists of words as the values. I am trying to create a function to add words to the players’ lists. I tried this code
#Dictionary of scrabble players and their words
players_words = {'alex':['BLUE', 'TENNIS' 'EXIT'], 'david':['EARTH', 'EYES', 'MACHINE'], 'john':['ERASER', 'BELLY', 'HUSKY'], 'jane': ['ZAP', 'COMA', 'PERIOD']}
#Define function to add a word for a player
def play_word(player, word):
players_words[player] += word
play_word('alex', 'WORK')
print(players_words)
The result I get is this:
{‘alex’: [‘BLUE’, ‘TENNISEXIT’, ‘W’, ‘O’, ‘R’, ‘K’], ‘david’: [‘EARTH’, ‘EYES’, ‘MACHINE’], ‘john’: [‘ERASER’, ‘BELLY’, ‘HUSKY’], ‘jane’: [‘ZAP’, ‘COMA’, ‘PERIOD’]}
Why does it split up the letters to separate entries in the list, and what code will add the new word to the list?
Thanks!