I'm trying to build a program in Python that, given a list of words and a list of letters, can determine what words can be made with 7 random letters from the list of letters.
I have code that shows all possible words from the list that are possible with all the letters in the list, but I need to change it to choose 7 random letters from the list, then see which words from the list are possible to make with those chosen letters.
Here's the code that uses all letters and determines what words are possible with them:
from collections import Counter
words = ['hi','how','are','you']
letters = ['h','i','b', 'a','r','e', 'l', 'y', 'o', 'u', 'x', 'b']
# For every word
for word in words:
# Convert the word into a dictionary
dict = Counter(word)
flag = 1
# For every letter in that word
for key in dict.keys():
# If that letter is not in the list of available letters, set the flag to 0
if key not in letters:
flag = 0
# If the flag remains 1 (meaning all letters in the word are in the letters list), then print the word.
if flag == 1:
print(word)
Right now, it correctly prints the possible words with all the letters, but I want it to choose 7 random letters from the list and print what words are possible.