title: Building a function from a string of k letters that outputs a list of words from a Valid Word List, and finds the word with the highest scrabble score
body: <p>So I have a function that outputs all words from a string</p>
  <p>However, I am struggling to integrate this into a list, currently, it outputs words in separate lists</p>
  <pre><code>def scrabble_score(word):
      total = 0 # Create score var
      for i in word: # Loop through given word
          total += score[i.lower()] #Lookup in dict, add total
      return total
  
  def charCount(word): 
      dict = {} 
      for i in word: 
          dict[i] = dict.get(i, 0) + 1
      return dict
    
    
  def possible_words(lwords, charSet): 
      for word in lwords: 
          flag = 1
          chars = charCount(word) 
          for key in chars: 
              if key not in charSet: 
                  flag = 0
              elif charSet.count(key) != chars[key]: 
                      flag = 0
  
          #for word in word_list:
          if flag == 1: 
              #word_value_dict = {}
              firstList = []
              #word_value_dict[word] = get_word_value(word, letter_values)
              firstList.append(word)
              #return word_value_dict
              print(scrabble_score(word), (word))
              print(firstList)
    
  if __name__ == &quot;__main__&quot;: 
      input = ['goo', 'bat', 'me', 'eat', 'goal', 'boy', 'run'] 
      charSet = ['e', 'o', 'b', 'a', 'm', 'g', 'l', 'b'] 
      possible_words(input, charSet) 
  </code></pre>
  <p>I also have a separate function that can find the word with the highest score from a list</p>
  <pre><code>def score(word):
      dic = {'D':2, 'C':2, 'L':2, 'P':2, 'B':3, 'N':3, 'F':4, 'G':4, 'H':4, 'V':4, 'J':5, 'Q':6, 'X':8, 'Y':8, 'Z':8}
      total = 0
      for char in word:
          total += dic.get(char.upper(), 0)
      return total
  #return highest score
  def best(lista):
      return max(lista, key=score)
  
  best(['goo', 'bat', 'me', 'eat', 'run'])
  </code></pre>
  <p>Output:</p>
  <pre><code>4 me
  ['me']
  5 goal
  ['goal']
  </code></pre>
  <p>Desired output:
  A list of all possible words</p>
  <pre><code>['me', 'goal']
  </code></pre>
  <p>OR
  A dictionary (or similar structure) with possible words as keys and score as values</p>
  <pre><code>{'me':4, 'goal':5]
  </code></pre>
  <p>I need a way of returning a lsit from the first function, and combining the two to find the highest score in that list</p>
  <p><strong>Part two:</strong></p>
  <p>I need to extend this to calculate the highest score for all combinations of letter sets from letter length 2-8, and the number of combinations we can have to generate such a score</p>