Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_valid_word(word, hand, word_list):
- """
- Returns True if word is in the word_list and is entirely
- composed of letters in the hand. Otherwise, returns False.
- Does not mutate hand or word_list.
- word: string
- hand: dictionary (string -> int)
- word_list: list of lowercase strings
- """
- # TO DO ...
- new_hand = {}
- new_hand.update(hand)
- if word in word_list:
- for letter in word:
- new_hand[letter] = new_hand.get(letter,0) - 1
- if new_hand.get(letter,0) < 0 :
- return False
- return True
- else:
- return False
Advertisement
Add Comment
Please, Sign In to add comment